I have a gradle file for building a JAR and publishing it in a maven repository on nexus server.
build.gradle file
publishing {
publications {
maven(MavenPublication) {
artifact shadowJar
}
}
repositories {
maven {
credentials {
username nexusUsername
password nexusPassword
}
if (IsSnapshot.toBoolean())
url "${nexusUrl}/repository/maven-snapshots/"
else
url "${nexusUrl}/repository/maven-releases/"
}
}
}
This task publishes a JAR file to the respective repository(snapshot/releases) based on the value of IsSnapshot.
I have one more variable: DoPublish. If DoPublish is true, then I want to publish the package; otherwise, I don't want to publish the package on nexus.
I am thinking I should set url to an empty string in such cases. Are there any better suggestions?
Output of gradle task
Publishing tasks
generatePomFileFor{module1}Publication - Generates the Maven POM file for publication 'module1'.
generatePomFileFor{module2}Publication - Generates the Maven POM file for publication 'module2'.
generatePomFileForMavenPublication - Generates the Maven POM file for publication 'maven'.
publish - Publishes all publications produced by this project.
publish{module1}PublicationToMavenLocal - Publishes Maven publication 'module1' to the local Maven repository.
publish{module1}PublicationToMavenRepository - Publishes Maven publication 'module1' to Maven repository 'maven'.
publish{module2}PublicationToMavenLocal - Publishes Maven publication 'module2' to the local Maven repository.
publish{module2}PublicationToMavenRepository - Publishes Maven publication 'module2' to Maven repository 'maven'.
publishMavenPublicationToMavenLocal - Publishes Maven publication 'maven' to the local Maven repository.
publishMavenPublicationToMavenRepository - Publishes Maven publication 'maven' to Maven repository 'maven'.
publishToMavenLocal - Publishes all Maven publications produced by this project to the local Maven cache.