gpt4 book ai didi

maven - 我可以在单个artifactId上发布多个 Artifact 吗?

转载 作者:行者123 更新时间:2023-12-03 03:25:36 27 4
gpt4 key购买 nike

我知道如何使用单个artifactId发布单个 Artifact 。我正在使用gradle发布我的 Artifact 。我的 Artifact 是.aar文件。
我像这样发布我的 Artifact :

publishing {
publications {
myPublication(MavenPublication) {
groupId 'com.example.project'
version '1.0.2'
artifactId 'myProject'
artifact("$buildDir/outputs/aar/mySDK-release.aar")
}
}

repositories {
mavenLocal()
}
}

现在,我想使用单个 artifactId发布多个 Artifact 。

最佳答案

TLDR:使用分类器。

由于您要发布到Maven,因此,请阅读他们有关Maven Coordinates的文档:

The POM defined above is the bare minimum that Maven allows. groupId:artifactId:version are all required fields (although, groupId and version do not need to be explicitly defined if they are inherited from a parent - more on inheritance later). The three fields act much like an address and timestamp in one. This marks a specific place in a repository, acting like a coordinate system for Maven projects:

  • groupId: This is generally unique amongst an organization or a project. For example, all core Maven artifacts do (well, should) live under the groupId org.apache.maven. Group ID's do not necessarily use the dot notation, for example, the junit project. Note that the dot-notated groupId does not have to correspond to the package structure that the project contains. It is, however, a good practice to follow. When stored within a repository, the group acts much like the Java packaging structure does in an operating system. The dots are replaced by OS specific directory separators (such as '/' in Unix) which becomes a relative directory structure from the base repository. In the example given, the org.codehaus.mojo group lives within the directory $M2_REPO/org/codehaus/mojo.
  • artifactId: The artifactId is generally the name that the project is known by. Although the groupId is important, people within the group will rarely mention the groupId in discussion (they are often all be the same ID, such as the MojoHaus project groupId: org.codehaus.mojo). It, along with the groupId, creates a key that separates this project from every other project in the world (at least, it should :) ). Along with the groupId, the artifactId fully defines the artifact's living quarters within the repository. In the case of the above project, my-project lives in $M2_REPO/org/codehaus/mojo/my-project.
  • version: This is the last piece of the naming puzzle. groupId:artifactId denotes a single project but they cannot delineate which incarnation of that project we are talking about. Do we want the junit:junit of 2018 (version 4.12), or of 2007 (version 3.8.2)? In short: code changes, those changes should be versioned, and this element keeps those versions in line. It is also used within an artifact's repository to separate versions from each other. my-project version 1.0 files live in the directory structure $M2_REPO/org/codehaus/mojo/my-project/1.0.

The three elements given above point to a specific version of a project, letting Maven know who we are dealing with, and when in its software lifecycle we want them.



显然,Maven坐标是 Artifact 特定版本的唯一标识符。可能不会有两个具有相同坐标的不同 Artifact 。

在单个 artifactId下发布两个 Artifact 的唯一方法是使用不同的版本。

如果检查 version order specs,则会看到可以使用所谓的限定符,例如 1.0.0-ALPHA1.0.0-RC。这实际上就是在Maven存储库中发布javadocs和源代码的方式:坐标为 a.b.c:d:1.0.0的 Artifact 可能会将javadocs发布在 a.b.c:d:1.0.0-javadoc下,而将源代码发布在 a.b.c:d:1.0.0-sources下。

因此,请使用限定词来解决问题。

限定词在Gradle的 Artifact 一侧指定:
publishing {
publications {
myPublication(MavenPublication) {
groupId 'com.example.project'
version '1.0.2'
artifactId 'myProject'


artifact("$buildDir/outputs/aar/mySDK-release-2.aar") {
// These values can also be specified in the task that generates the AAR.
classifier "q1"
}
artifact("$buildDir/outputs/aar/mySDK-release-1.aar") {
classifier "q2"
}
}
}
}

关于maven - 我可以在单个artifactId上发布多个 Artifact 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61521257/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com