Why is Gradle being ignored by groupId / artifactId?

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 assembly call I'm using:

gradle clean build groovydoc sourcesJar createPom -Pversion=SNAPSHOT

      

When I ran this:

  • The POM file is created with groupId

    , artifactId

    and version

    , everything renders correctly inside the XML; but
  • The resulting JAR name is whatever folder the project resides in. For example, if the name of my project root is "fizz" and the above build file is in fizz/build.gradle

    , then calling build above will output fizz-<version>.jar

    (where <version>

    is whatever value I specify on the command line) If I now rename the directory fizz/

    to buzz/

    and re-run the same assembly call will be created buzz-<version>.jar

    .

My question is, how / where (which file) am I hard-coded groupId

and artifactId

internally so that myapp-<version>.jar

is generated, regardless of the name of the project root?

+3


source to share


1 answer


You need settings.gradle

in the root of the project, and inside you install rootProject.name = 'artifactId'

, this will fix the project name.



The grouping and version can be set in the build.gradle file using the group

and properties version

.

+7


source







All Articles