Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
242 views
in Technique[技术] by (71.8m points)

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

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...