Here is my Gradle build:
apply plugin: 'groovy'
apply plugin: 'maven'
group = 'myorg'
repositories {
mavenCentral()
}
dependencies {
compile 'org.codehaus.groovy:groovy-all:2.3.3'
compile 'org.apache.httpcomponents:httpclient:4.3.5'
compile 'org.slf4j:slf4j-api:1.7.5'
testCompile 'junit:junit:4.11'
}
task sourcesJar(type: Jar, dependsOn: classes) {
classifier = 'sources'
from sourceSets.main.allSource
}
artifacts {
archives sourcesJar
}
task createPom << {
pom {
project {
groupId group
artifactId "myapp"
version version
}
}.writeTo("build/libs/pom.xml")
}
And the build invocation I am using:
gradle clean build groovydoc sourcesJar createPom -Pversion=SNAPSHOT
When I run this:
groupId
, artifactId
and version
all appearing correctly inside the XML; butfizz/build.gradle
, then the build invocation above produces fizz-<version>.jar
(where <version>
is whatever value I specify on the command line). If I now rename the fizz/
directory to buzz/
and re-run the same build invocation, a buzz-<version>.jar
will be produced.My question: how/where (what file) do I hardcode groupId
and artifactId
inside so that myapp-<version>.jar
gets built, regardless of the name of the project root directory?
You need a settings.gradle
in the project root and inside you set the rootProject.name = 'artifactId'
this will fix the name of the project.
The groupId and version can be set in the build.gradle file via the group
and version
properties.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With