Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is Gradle ignoring groupId/artifactId?

Tags:

gradle

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:

  • The POM file is created with groupId, artifactId and version all appearing correctly inside the XML; but
  • The name of the resultant JAR is whatever folder the project is rooted under. For instance, if the name of my project root is "fizz", and the buildfile above is located at fizz/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?

like image 907
smeeb Avatar asked Feb 12 '23 18:02

smeeb


1 Answers

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.

like image 73
Leonard Brünings Avatar answered Feb 15 '23 11:02

Leonard Brünings