有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java Gradle覆盖zip存档的默认“artifactId”

我正在将一些my-libs.zip上传到S3,但无法获得覆盖默认artifactId的语法。当前artifactId,它是从settings.gradle拾取的project.name

注意:我不想在settings.gradle中更改我的project.name

apply plugin: 'maven-publish'

artifacts {
    someArtifact file: file('image/my-libs.zip'), name: 'my-libs', type: 'zip'
}

uploadSomeArtifact {
    description 'Uploads some artifact.'
    group = "com.mypackage"
    version = "dummy-SNAPSHOT"
    repositories {
        maven {
            url "s3://my-mvn-repo/snapshot/com/mypackage"
            authentication {
                awsIm(AwsImAuthentication)
            }
        }
    }
}

共 (1) 个答案

  1. # 1 楼答案

    首先,出于某种原因,您同时应用了^{} plugin^{} plugin。两个插件的功能基本相同,但第一个插件很久以前就被弃用了。您应该决定使用哪个插件,我建议您使用maven-publish插件


    尽管如此,我们还是来看看旧的maven插件的文档。它说:

    Maven Element: artifactId
    Default value: uploadTask.repositories.mavenDeployer.pom.artifactId (if set) or archiveTask.archiveBaseName

    后来:

    When you set the archiveTask.archiveBaseName property to a value other than the default, you’ll also have to set uploadTask.repositories.mavenDeployer.pom.artifactId to the same value. Otherwise, the project at hand may be referenced with the wrong artifact ID from generated POMs for other projects in the same build.

    这里,^{}指的是一个不推荐使用的方法,它被添加到RepositoryHandler后面的repositories中。似乎需要使用这种不推荐的方法来指定目标存储库,而不是使用您使用的maven方法。遗憾的是,可能无法将AWS身份验证和s3协议用于这个旧接口


    现在让我们看看新的maven-publish插件。使用此插件,您不再定义工件和配置Upload任务。相反,您定义了发布和存储库,插件将为发布和存储库的每个组合生成一个任务:

    publishing {
        publications {
            myLibs(MavenPublication) {
                groupId = 'com.mypackage'
                artifactId = 'my-libs'
                version = 'dummy-SNAPSHOT'
                artifact (file('image/my-libs.zip')) {
                    classifier 'src'
                    extension 'zip'
                }
            }
        }
        repositories {
            maven {
                url 's3://my-mvn-repo/snapshot/com/mypackage'
                authentication {
                    awsIm(AwsImAuthentication)
                }
            }
        }
    }
    

    如您所见,repositories部分保持不变,publications部分允许您以与groupIdversion相同的方式定义artifactId