Does Gradle support classifiers for Ivy repositori

2019-05-10 04:22发布

问题:

I'm trying to retrieve Gradle dependencies from an Ivy repository (in Artifactory) based on a classifier (to filter DLLs containing native code to get just the ones for the relevant processor architecture). My build.gradle looks like this:

repositories {
   ivy {
      name 'prebuilts'
      url "${repositoryServer}/prebuilts"
      credentials {
         username artifactoryUser
         password artifactoryPassword
      }
      layout 'pattern', {
         artifact '[organisation]/[module]/[revision]/[artifact](-[classifier]).[ext]'
         ivy '[organisation]/[module]/[revision]/ivy-[revision].xml'
      }
   }
}

configurations {
    example
}

dependencies {
    example group: 'ThirdParty', name: 'jogl_JSR-231', version: '1.1.0.1', configuration: 'nativeRuntime', classifier: 'release_win32'
}

project.configurations.example.each {
    println it
}

The ivy.xml for that dependency looks like this:

     <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
     <ivy-module version="2.0">
     <info organisation="ThirdParty" module="jogl_JSR-231" revision="1.1.0.1" status="release" publication="20130508143052"/>
     <configurations>
         <conf name="nativeRuntime" description="Native artifacts for running tests." visibility="public"/>
         <conf name="archives" description="Configuration for archive artifacts." visibility="public"/>
         <conf name="default" extends="runtime" description="Configuration for default artifacts." visibility="public"/>
         <conf name="compile" description="Classpath for compiling the main sources." visibility="private"/>
         <conf name="runtime" extends="compile" description="Classpath for running the compiled main classes." visibility="private"/>
         <conf name="testCompile" extends="compile" description="Classpath for compiling the test sources." visibility="private"/>
         <conf name="testRuntime" extends="runtime,testCompile" description="Classpath for running the compiled test classes." visibility="private"/>
         <conf name="cppCompile" description="Configuration for API artifacts (headers)." visibility="public"/>
         <conf name="nativeArchives" description="Configuration for native archive artifacts." visibility="public"/>
     </configurations>
     <publications>
         <artifact name="gluegen-rt" type="jar" ext="jar" conf="archives,runtime"/>
         <artifact name="jogl" type="jar" ext="jar" conf="archives,runtime"/>
         <artifact xmlns:m="http://ant.apache.org/ant/maven" name="gluegen-rt" type="jar" ext="jar" conf="archives" m:classifier="sources"/>
         <artifact xmlns:m="http://ant.apache.org/ant/maven" name="jogl" type="jar" ext="jar" conf="archives" m:classifier="sources"/>
         <artifact xmlns:m="http://ant.apache.org/ant/maven" name="gluegen-rt" type="dll" ext="dll" conf="nativeArchives,nativeRuntime" m:classifier="release_win32"/>
         <artifact xmlns:m="http://ant.apache.org/ant/maven" name="jogl" type="dll" ext="dll" conf="nativeArchives,nativeRuntime" m:classifier="release_win32"/>
         <artifact xmlns:m="http://ant.apache.org/ant/maven" name="jogl_awt" type="dll" ext="dll" conf="nativeArchives,nativeRuntime" m:classifier="release_win32"/>
         <artifact xmlns:m="http://ant.apache.org/ant/maven" name="jogl_cg" type="dll" ext="dll" conf="nativeArchives,nativeRuntime" m:classifier="release_win32"/>
         <artifact xmlns:m="http://ant.apache.org/ant/maven" name="gluegen-rt" type="dll" ext="dll" conf="nativeArchives,nativeRuntime" m:classifier="release_x64"/>
         <artifact xmlns:m="http://ant.apache.org/ant/maven" name="jogl" type="dll" ext="dll" conf="nativeArchives,nativeRuntime" m:classifier="release_x64"/>
         <artifact xmlns:m="http://ant.apache.org/ant/maven" name="jogl_awt" type="dll" ext="dll" conf="nativeArchives,nativeRuntime" m:classifier="release_x64"/>
         <artifact xmlns:m="http://ant.apache.org/ant/maven" name="jogl_cg" type="dll" ext="dll" conf="nativeArchives,nativeRuntime" m:classifier="release_x64"/>
         <artifact name="joglBuildRecord" type="txt" ext="txt" conf="archives"/>
     </publications>
     <dependencies/>
     </ivy-module>

I get the following error:

FAILURE: Build failed with an exception.

* Where:
Build file 'C:\tmp\gradle-scratch\dependencies-by-classifier\build.gradle' line: 25

* What went wrong:
A problem occurred evaluating root project 'dependencies-by-classifier'.
> Could not resolve all dependencies for configuration ':example'.
   > Artifact 'ThirdParty:jogl_JSR-231:1.1.0.1:release_win32@jar' not found.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

I'm not at all sure what I'm doing wrong here. Is it the classifier? If I remove it everything works (although obviously I don't get what I want).

回答1:

Ivy does not support classifiers. See the syntax of Ivy patterns at the Ivy documentation: http://ant.apache.org/ivy/history/latest-milestone/concept.html#patterns

Where did you get the Ivy definition of JOGL? If you made it yourself I would change the configurations to:

<conf name="nativeRuntime32" .../>
<conf name="nativeRuntime64" .../>
<conf name="nativeRuntime" extends="nativeRuntime32,nativeRuntime64" .../>

In Gradle you can than use configuration nativeRuntime32 to get the artifacts that you need.

If you did not write the Ivy definition, you might consider asking the JOGL developers to add more flexible Ivy configurations so people can more easily select the artifacts they need.



标签: gradle