1

I'm using this plugin:

apply plugin: 'maven'

How can I specify an artifactId that is NOT the project/folder name?

I already use this:

jar {
  archiveName = "myproject.jar"
}

But this is not what the plugin uses.

benji
  • 2,331
  • 6
  • 33
  • 62
  • http://stackoverflow.com/a/24827804/3166303 – leeor Apr 22 '16 at 23:56
  • +leeor not the same plugin, your link is about 'maven-publish' – benji Apr 23 '16 at 00:03
  • oops, sorry about that, misread. – leeor Apr 23 '16 at 00:06
  • 1
    Is there a reason you do not use the new maven-publish plugin but the old maven plugin? – Vampire Apr 23 '16 at 01:40
  • Switching the project-name in the settings.gradle is not an option? As far as I know the artifactId == projectName. If you want to change it in your settings.gradle (right beside your build.gradle) just add rootProject.name='YourNewName' – TobiSH Apr 23 '16 at 08:57

2 Answers2

2

Do you have an uploadArchives section in your build.gradle? You can do this to customize the published artifact:

uploadArchives {
    repositories {
        mavenDeployer {
            repository(url: "file://localhost/tmp/myRepo/")
            pom.version = '1.0Maven'
            pom.artifactId = 'myMavenName'
        }
    }
}

See maven plugin documentation for reference

RaGe
  • 22,696
  • 11
  • 72
  • 104
0

From the Users Guide:

31.6.4. Maven POM generation

When deploying an artifact to a Maven repository, Gradle automatically generates a POM for it. The groupId, artifactId, version and packaging elements used for the POM default to the values shown in the table below. The dependency elements are created from the project's dependency declarations.

Table 31.5. Default Values for Maven POM generation Maven Element Default Value groupId project.group artifactId uploadTask.repositories.mavenDeployer.pom.artifactId (if set) or archiveTask.baseName. version project.version packaging archiveTask.extension

Here, uploadTask and archiveTask refer to the tasks used for uploading and generating the archive, respectively (for example uploadArchives and jar). archiveTask.baseName defaults to project.archivesBaseName which in turn defaults to project.name.

benji
  • 2,331
  • 6
  • 33
  • 62
Vampire
  • 35,631
  • 4
  • 76
  • 102
  • This answer is not helpful to someone who js not aware of the ins and outs of gradle. It does not give an example of how to set the artifactId, so that it gets picked up in all relevant places. – Felix Leipold Mar 22 '18 at 11:09
  • Why not? It tells you that the artifact id is taken from `uploadTask.repositories.mavenDeployer.pom.artifactId` if set or otherwise from `archiveTask.baseName`, so those are the values you have to adjust. Which one to use depends on the wanted effect, that I cannot guess. If running the `jar` task should also name the JAR accordingly, the `jar.baseName` should be changed, if only the published JAR should be named accordingly, the `uploadTask` configuration can be used. – Vampire Mar 22 '18 at 13:43