Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>To upload a jar via gradle you must declare that jar as a publish artifact and add it to a specific configuration using the artifacts closure:</p> <pre><code>apply plugin:'maven' configurations{ allJars } artifacts{ allJars file("path/to/jarFile.jar") } </code></pre> <p>now you can configure the dynamically created uploadAllJars task:</p> <pre><code>uploadAllJars { repositories { mavenDeployer { repository(url: 'http://localhost:8081/artifactory/acme') { authentication(userName: 'admin', password: 'password'); } } } </code></pre> <p>The problem is that you want to upload multiple artifacts. To achieve that you need some more dynamic in your build script. The dynamic creation of publishartifacts for all discovered jars can be wrapped in a task. In my example the discoverAllJars task simply looks in a specified folder for jar files. Here you need to implement your own logic to lookup the jars in your tgz archive.</p> <pre><code>group = "org.acme" version = "1.0-SNAPSHOT" task discoverAllJars{ ext.discoveredFiles = [] doLast{ file("jars").eachFile{file -&gt; if(file.name.endsWith("jar")){ println "found file ${file.name}" discoveredFiles &lt;&lt; file artifacts{ allJars file } } } } } </code></pre> <p>To be able to upload multiple artifacts within the uploadAllJars task you have to use pom filter. For details about pom filter have a look at the gradle userguide at <a href="http://www.gradle.org/docs/current/userguide/maven_plugin.html#uploading_to_maven_repositories" rel="noreferrer">http://www.gradle.org/docs/current/userguide/maven_plugin.html#uploading_to_maven_repositories</a></p> <p>Since we moved the configuration of the published artifacts into the execution phase of gradle we must configure the uploadAllJars in the execution phase too. Therefore I'd create a configureUploadAllJars task. Note how we reference the jar files discovered by using 'discoverAllJars.discoveredFiles':</p> <pre><code> task configureUploadAllJars{ dependsOn discoverAllJars doLast{ uploadAllJars { repositories { mavenDeployer { repository(url: 'http://yourrepository/') { authentication(userName: 'admin', password: 'password'); } discoverAllJars.discoveredFiles.each{discoveredFile -&gt; def filterName = discoveredFile.name - ".jar" addFilter(filterName) { artifact, file -&gt; file.name == discoveredFile.name } pom(filterName).artifactId = filterName } } } } } } </code></pre> <p>Now you just need to add a dependency between uploadAllJars and configureUploadAllJars:</p> <pre><code>uploadAllJars.dependsOn configureUploadAllJars </code></pre> <p>This example uses the same group and version for all discovered jar files and the jar name as artifactId. you can change this as you like using the pom filter mechanism.</p> <p>hope that helped,</p> <p>cheers, René</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload