How do you set the maven artifact ID of a gradle project?

后端 未结 7 776
甜味超标
甜味超标 2021-01-30 03:48

From the gradle maven-publish plugin\'s documentation, it\'s clear that you set the groupId and version of the project directly in build.gradle

7条回答
  •  梦谈多话
    2021-01-30 04:11

    If you have a multi-module project, and you want the artifacts' names to differ from the Directory (which is set in the settings.gradle), then I think a better approach is to have a jar block for each sub-project, and there you can write the baseName, which will be the artifact-id. Then, rather than re-writing the publishing/publications block for each sub-project, you write it only once in the main build.gradle this way:

    for each sub-project build.gradle:

    jar {
        baseName = 'new-artifact-name-A'  //A beacause you also have B, C modules... 
    }
    

    in the main build.gradle:

    publishing {
        publications {
            mavenJava(MavenPublication) {
               artifactId jar.baseName
               from components.java
            }
        }
    }
    

提交回复
热议问题