Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/sorting/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
为什么Gradle忽略了groupId/artifactId?_Gradle - Fatal编程技术网

为什么Gradle忽略了groupId/artifactId?

为什么Gradle忽略了groupId/artifactId?,gradle,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 '

这是我的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")
}
当我运行此命令时:

  • POM文件是使用
    groupId
    artifactId
    version
    创建的,所有这些文件都正确显示在XML中;但是
  • 结果JAR的名称是项目根目录下的任何文件夹。例如,如果我的项目根目录名为“fizz”,并且上面的构建文件位于
    fizz/build.gradle
    ,那么上面的构建调用将生成
    fizz-.jar
    (其中
    是我在命令行上指定的任何值)。如果我现在将
    fizz/
    目录重命名为
    buzz/
    并重新运行相同的构建调用,将生成一个
    buzz-.jar

我的问题:如何/在哪里(什么文件)硬编码
groupId
artifactId
以便构建
myapp-.jar
,不管项目根目录的名称是什么?

您需要在项目根目录中设置一个
设置。gradle
,并在其中设置
rootProject.name='artifactId'
这将修复项目的名称


groupId和版本可以通过
版本
属性在build.gradle文件中设置。

谢谢@Leonard Brunings(+1)-但是请查看我的更改(如上)。当我打开生成的
pom.xml
文件时,我看到
groupId
null
。我能做些什么来纠正这个问题?再次感谢!如果查看,您会发现您根本不需要覆盖pom中的属性,因为它们默认为您的项目属性。在这里,您似乎可以找到您要查找的内容:
gradle clean build groovydoc sourcesJar createPom -Pversion=SNAPSHOT