简体   繁体   中英

Uploading artifacts from multiple configurations to maven in gradle

I cannot seem to be able to publish a second set of jars to a local maven repo using a separate upload task, different to uploadArchives . Here's my setup:

uploadArchives {
  repositories {
    mavenDeployer {
      repository(url: project.releaseRepoUrl)
      snapshotRepository(url: project.snapshotRepoUrl)
    }
  }
}

task sourcesJar(type: Jar){ ... }

artifacts{
  archives sourcesJar
}

The above works as expected. Then I have an additional configuration

configurations{
  guiceArchives
}

task guiceJar(type: Jar){ ... }

task guiceSourcesJar(type: Jar){ ... }

artifacts{
  guiceArchives guiceJar
  guiceArchives guiceSourcesJar
  //archives guiceJar
  //archives guiceSourcesJar
}

Executing gradle uploadArchives works OK, but gradle uploadGuiceArchives does nothing:

:core:guiceClasses UP-TO-DATE
:core:guiceJar UP-TO-DATE
:core:guiceSourcesJar UP-TO-DATE
:core:jar UP-TO-DATE
:core:sourcesJar UP-TO-DATE
:core:uploadArchives

BUILD FINISHED

Individual guiceJar and guiceSourcesJar tasks work fine by themselves, and printing out the contents of guiceArchives configuration also reveals that jars are correctly included as artifacts.

I tried temporarily assigning guiceJar and guiceSourcesJar to the archives configuration, which makes it complain saying:

A POM cannot have multiple artifacts with the same type and classifier.

Which is exactly what the manual says . So I assumed that it is this artifact clash that was the cause of the problem.

So I fixed it using addFilter as the manual suggests, which worked great but only when guiceJar and guiceSourcesJar are assigned to archives . When I assign them back to guiceArchives and try gradle uploadGuiceArchives it still does nothing.

Is there no way to upload multiple artifacts with different upload tasks?

Solution:

Here's the update with the solution provided by @Peter Niederwieser.

Just add this:

uploadGuiceArchives {
  repositories {
    mavenDeployer {
      repository(url: project.releaseRepoUrl)
      snapshotRepository(url: project.snapshotRepoUrl)
    }
  }
}

Note: the addFilter is not needed.

Thanks!

Edit2:

For completeness, the project.releaseRepoUrl and project.snapshotRepoUrl are set to a local maven repository as follows:

project.ext{
  releaseRepoUrl = "file://${project(':').projectDir}/../mvn-repo/releases"
  snapshotRepoUrl = "file://${project(':').projectDir}/../mvn-repo/snapshots"
}

难道说你没有为定义库uploadGuiceArchives像你这样的uploadArchives

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM