为什么Gradle忽略groupId/artifactId?

sme*_*eeb 3 gradle

这是我的Gradle构建:

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")
}
Run Code Online (Sandbox Code Playgroud)

我正在使用的构建调用:

gradle clean build groovydoc sourcesJar createPom -Pversion=SNAPSHOT
Run Code Online (Sandbox Code Playgroud)

当我运行这个:

  • POM文件是用XML 创建的groupId,artifactId并且version都在XML中正确显示; 但
  • 生成的JAR的名称是项目所在的任何文件夹.例如,如果我的项目root的名称是"fizz",并且上面的构建文件位于fizz/build.gradle,则上面的构建调用会产生fizz-<version>.jar(其中<version>是我在命令行中指定的任何值).如果我现在将fizz/目录重命名为buzz/并重新运行相同的构建调用,buzz-<version>.jar则将生成a.

我的问题:无论项目根目录的名称如何,如何/在哪里(什么文件)进行硬编码groupIdartifactId内部以便myapp-<version>.jar构建?

Leo*_*ngs 8

您需要settings.gradle在项目根目录和内部设置,rootProject.name = 'artifactId'这将修复项目的名称.

可以通过groupversion属性在build.gradle文件中设置groupId和version .