Gradle: retrieve only one of multiple published artifacts?

前端 未结 2 468
隐瞒了意图╮
隐瞒了意图╮ 2021-01-21 06:46

I\'ve got an Ivy repository with multiple published artifacts, something like this:

/mygroup/mymodule/1.1.1/mymodule-1.1.1.jar
/mygroup/mymodule/1.1.1/mymodule-c         


        
相关标签:
2条回答
  • 2021-01-21 07:28

    The Ivy module descriptor doesn't assign the artifacts to different configurations, hence it's not possible to retrieve them independently. If all you want is to only put one of the two artifacts on the compile class path, something like the following should work:

    configurations {
        mymodule
    }
    
    dependencies {
        mymodule 'mygroup:mymodule:1.1.1'
        compile configurations.mymodule.filter { it.name == 'mymodule-client-1.1.1.jar' } 
    }
    
    0 讨论(0)
  • 2021-01-21 07:30

    Managed to find the appropriate line after a lot of trial and error:

    compile ('mygroup:mymodule:1.1.1:client@jar')
    

    I think it only works because the "client" is an extension of the module name (called a classifier apparently). If I'd had something named differently, I'm not sure how I'd have resolved it.

    I found the example that gave me the clue here: http://scratchpad.pietschy.com/gradle/dependency_management.html

    20.2.2.2. Artifact only notation An artifact only notation creates a module dependency which only downloads one artifact file. The notation for such a dependency follows the pattern: [group]:[artifact]:[version]@[extension] or [group]:[artifact]:[version]:[classifier]@[extension]. For example:

    dependencies { compile "org.apache.ant:ant-junit:1.7.0@jar" }

    0 讨论(0)
提交回复
热议问题