Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Upload sources to nexus repository with gradle

Tags:

I successfully uploaded my jars to a nexus repository using the maven plugin for gradle but it didn't upload the sources. This is my configuration:

uploadArchives {     repositories{         mavenDeployer {             repository(url: "http://...") {                  authentication(userName: "user", password: "myPassword")             }         }     } } 

I searched and found that I can add the sources by adding a new task.

task sourcesJar(type: Jar, dependsOn:classes) {      classifier = 'sources'      from sourceSets.main.allSource }  artifacts {      archives sourcesJar } 

This works fine but I think there must be a better solution by configuring the maven plugin, something like uploadSource = true like this:

uploadArchives {     repositories{         mavenDeployer {             repository(url: "http://...") {                  authentication(userName: "user", password: "myPassword")             }             uploadSources = true         }     } } 
like image 714
gllambi Avatar asked Feb 20 '15 13:02

gllambi


People also ask

Does Nexus support gradle?

Gradle Nexus Publish Plugin. This Gradle plugin is a turn-key solution for publishing to Nexus. You can use it to publish your artifacts to any Nexus instance (internal or public). It is great for publishing your open source to Sonatype, and then to Maven Central, in a fully automated fashion.


1 Answers

There is no better solution than what you described yourself. The gradle maven plugin is uploading all artifacts generated in the current project. That's why you have to explicitly create a "sources" artifact.

The situation also doesn't change when using the new maven-publish plugin. Here, you also need to explicitly define additional artifacts:

task sourceJar(type: Jar) {     from sourceSets.main.allJava }  publishing {     publications {         mavenJava(MavenPublication) {             from components.java              artifact sourceJar {                 classifier "sources"             }         }     } } 

The reason is that gradle is more about being a general build tool and not bound to pure Java projects.

like image 77
Sebi Avatar answered Sep 28 '22 19:09

Sebi