英文:
Gradle override default 'artifactId' of a zip archive
问题
我正在将一些 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 '上传某些构件。';
group = "com.mypackage";
version = "dummy-SNAPSHOT";
repositories {
maven {
url "s3://my-mvn-repo/snapshot/com/mypackage";
authentication {
awsIm(AwsImAuthentication);
}
}
}
}
英文:
I'm uploading some my-libs.zip
to S3 and not able to get the syntaxes to override default artifactId
. Currently the artifactId
, it is picked up is project.name
from settings.gradle
Note: I don't want to change my project.name
in settings.gradle
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
首先,由于某种原因,您同时应用了maven
插件和maven-publish
插件。这两个插件基本上执行相同的功能,但第一个插件在很长时间前就已被弃用。您应该决定使用哪个插件,我建议使用maven-publish
插件。
不过,让我们来看一下旧maven
插件的文档。它说:
> Maven元素: artifactId
> 默认值: uploadTask.repositories.mavenDeployer.pom.artifactId
(如果已设置),或者archiveTask.archiveBaseName
然后:
> 当您将archiveTask.archiveBaseName
属性设置为与默认值不同的值时,您还必须将uploadTask.repositories.mavenDeployer.pom.artifactId
设置为相同的值。否则,当前的项目在为同一构建中的其他项目生成的POM中可能会引用错误的artifact ID。
在这里,mavenDeployer
是一个被添加到RepositoryHandler
内部repositories
之后的被弃用的方法。似乎需要使用这种被弃用的方式来指定目标存储库,而不是使用您使用的maven
方法。遗憾的是,可能无法在这种旧接口中同时使用AWS身份验证和s3
协议。
现在让我们来看一下新的maven-publish
插件。使用这个插件,您不再定义artifacts并配置Upload
任务。相反,您定义publications和repositories,插件将为每个publication和repository的组合生成一个任务:
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
部分允许您以与groupId
和version
相同的方式定义artifactId
。
英文:
First of all, for some reason you apply both the maven
plugin and the maven-publish
plugin. Both plugins do basically the same, but the first one was deprecated a long time ago. You should decide which plugin to use and I suggest to use the maven-publish
plugin.
Nevertheless, lets take a look at the documentation of the old maven
plugin. It says:
> Maven Element: artifactId
> Default value: uploadTask.repositories.mavenDeployer.pom.artifactId
(if set) or archiveTask.archiveBaseName
And later:
> 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.
Here, mavenDeployer
refers to a deprecated method that gets added to the RepositoryHandler
behind repositories
. It seems like it is required to use this deprecated way to specify the target repository instead using the maven
method you used. Sadly, there is probably no way to use the AWS authentication and the s3
protocol with this old interface.
Let's now take a look at the new maven-publish
plugin. With this plugin, you no longer define artifacts and configure Upload
tasks. Instead, you define publications and repositories and the plugin will generate a task for each combination of a publication and a repository:
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)
}
}
}
}
As you can see, the repositories
part stays the same and the publications
part allows you to define the artifactId
in the same way as the groupId
and the version
.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论