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

后端 未结 7 595
甜味超标
甜味超标 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:09

    From 36.2.3. Identity values in the generated POM

    publishing {
        publications {
            maven(MavenPublication) {
                groupId 'org.gradle.sample'
                artifactId 'project1-sample'
                version '1.1'
    
                from components.java
            }
        }
    }
    

    The artifact ID defaults to the project name configured in settings.gradle, which in turn defaults to the project directory's name.

    You'll need the appropriate plugin.

    plugins {
        id 'maven-publish'
    }
    
    0 讨论(0)
  • 2021-01-30 04:10

    However, the artifactId appears to be taken from the name of the folder you are working within. Is there a way to set the artifactId explicitly?

    A simple answer to this is to set the jar.baseName which then overrides the directory name.

    // changes the name of the jar from the directory name
    jar.baseName = 'some_arifact_name';
    

    This seems to work for me.

    0 讨论(0)
  • 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
            }
        }
    }
    
    0 讨论(0)
  • 2021-01-30 04:14

    For building android and publishing to artifactory using jenkins, I configured the settings below in the app modules's build.gradle for configuring group id, artifact id, and version.

    apply plugin: 'com.android.application'
    
    android {
        compileSdkVersion 21
        buildToolsVersion "21.1.2"
    
        group "com.company.division.productgroup" //add group id
        version "8.8.8" //add version
    
        defaultConfig {
    
            minSdkVersion 9
            targetSdkVersion 21
            versionCode 32
            versionName "$version"
            archivesBaseName = "android-appname" //add artifact id
    
        }
    
    0 讨论(0)
  • 2021-01-30 04:15

    In Gradle, you can set jar.archiveName to override the use of the working folder's name...

    group = 'com.example'
    version = '0.0.1-SNAPSHOT'
    jar.archiveName = "myproject-0.0.1-SNAPSHOT.jar"
    
    0 讨论(0)
  • 2021-01-30 04:31

    Related to the root settings.gradle file, you can change the name of the root project with:

    rootProject.name = 'myproject'
    

    But if you want to change the name of a sub-project (for example, the default "app" sub-project of an AndroidStudio project), you can do something like this, still in the root settings.gradle file:

    rootProject.children.each {
        it.name = ('app' == it.name ? 'MyAppName' : it.name)
    }
    
    0 讨论(0)
提交回复
热议问题