gradle - how to declare a dependency of a jar in a jar

梦想与她 提交于 2019-11-28 11:01:28

问题


Using gradle, I am consuming a build from an archiva repository. One of the jars (javax.jms_1.1.0.200810061358.jar) has the following content:

about.html
about_files
LICENSE.txt
jms.jar
META-INF
MANIFEST.MF

The jar I need is actually the jms.jar inside this javax.jms_1.1.0.200810061358.jar

The only way I've been able to consume this jar is by pulling jms.jar out of the repository's javax.jms_1.1.0.200810081358.jar and saving it to the file system and consuming it via:

repositories { flatDir: my_dir_with_jms.jar_in_it}

someone on the gradle list suggested using an Ivy packager resolver.

I looked at this link and was left very confused. I do have other ivy resolvers set up like this:

addIvyPattern 'http://archivaserver:8080/archiva/repository/osgi-internal/[organisation]/[module]/[revision]/ivy_[revision].xml'
   addArtifactPattern
"http://archivaserver:8080/archiva/repository/osgi-official/[organisation]/[organisation]/[module]_[revision](-[classifier]).[ext]"

Anyone know of a good solution to this?


回答1:


Resolving a dependency inside a dependency would require the use of the ivy packager resolver.

I've never configured the package resolver from within Gradle, but I think it would work something like the following (Referencing webpage)

repositories {
    add(new org.apache.ivy.plugins.resolver.packager.PackagerResolver()) {
        name = 'local Ivy packagers'

        buildRoot = file("${gradle.gradleUserHomeDir}/packager/build")
        resourceCache = file("${gradle.gradleUserHomeDir}/packager/cache")

        addIvyPattern      "file:///${project.rootDir}/ivy/[organisation]/[module]/[revision]/ivy.xml"
        addArtifactPattern "file:///${project.rootDir}/ivy/[organisation]/[module]/[revision]/packager.xml"
    }
}

dependencies {
    compile group: 'org.myorg', name: 'jms', version: '1.1.0.200810061358'
}

The resolver requires the following files for the declared dependency:

ivy/org.myorg/jms/1.1.0.200810061358/ivy.xml
ivy/org.myorg/jms/1.1.0.200810061358/packager.xml

ivy.xml

Describes the module and in this case declares what artifacts are published:

<ivy-module version="2.0">
    <info organisation="org.myorg" module="jms" revision="1.1.0.200810061358" status="release"/>

    <publications>
        <artifact name="jms" type="jar"/>
    </publications>

</ivy-module>

packager.xml

Describes where the enclosing archive is located and instructions on how to extract jms.jar:

<packager-module version="1.0">

    <resource dest="archive" url="http://archivaserver:8080/archiva/repository/??/javax.jms_1.1.0.200810061358.jar" sha1="????"/>

    <build>
        <move file="archive/jms.jar" tofile="artifacts/jars/jms.jar"/>
    </build>

</packager-module>

The content under the build tag is used to generate an ANT script. For more details read the "Packaging instructions" section of the ivy documentation



来源:https://stackoverflow.com/questions/3445696/gradle-how-to-declare-a-dependency-of-a-jar-in-a-jar

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!