maven-publish插件中versionMapping的作用是什么

What is the role of versionMapping in maven-publish plugin

如果我们必须使用 maven-publish 插件生成 java 库,哪个选项更可取

选项 1:

publishing {
    publications {
        mavenJava(MavenPublication) {
            from components.java
        }
    }
}

选项 2:

publishing {
    publications {
        mavenJava(MavenPublication) {
            from components.java
            versionMapping {
                allVariants {
                    fromResolutionResult()
                }
            }
        }
    }
}

What is the role of versionMapping in maven-publish plugin

根据 docs:

Two strategies are supported for publishing dependencies:

-- snip

This is done by using the versionMapping DSL method

What option would be preferable

这完全取决于您的用途case/needs。如文档中所述,依赖关系有两种策略:声明版本和解析版本。您使用哪一个完全取决于您的用例或需求。