gpt4 book ai didi

maven - 将 grails3 插件发布到 Artifact - 生成的 pom 的差异

转载 作者:行者123 更新时间:2023-12-03 05:01:29 24 4
gpt4 key购买 nike

我正在尝试将 grails 3 插件的快照发布到远程 maven 存储库(Artifactory)。这是我的构建脚本:

import org.springframework.util.StringUtils

buildscript {
ext {
grailsVersion = project.grailsVersion
}
repositories {
jcenter()
mavenLocal()
mavenCentral()
maven { url "https://repo.grails.org/grails/core" }
maven { url "${artifactory_contextUrl}"
credentials {
username "${artifactory_user}"
password "${artifactory_password}"
}
name = "remote-maven-repo"
}
}
dependencies {
classpath "org.grails:grails-gradle-plugin:$grailsVersion"
classpath "org.jfrog.buildinfo:build-info-extractor-gradle:3.1.2"
}
}

plugins {
id "io.spring.dependency-management" version "0.5.2.RELEASE"
id "com.jfrog.bintray" version "1.2"
}

String baseVersion = "0.1.0-%customer%-SNAPSHOT"
String currentVersion = "$baseVersion".replaceAll('%customer%',property('plugin.default.customer').toUpperCase())
version currentVersion
group "org.grails.plugins"

apply plugin: 'maven'
apply plugin: 'maven-publish'
apply plugin: "com.jfrog.artifactory"
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: "spring-boot"
apply plugin: "org.grails.grails-plugin"
apply plugin: "org.grails.grails-gsp"

println "Current customer mode: [${property("plugin.default.customer")}]"

ext {
grailsVersion = project.grailsVersion
gradleWrapperVersion = project.gradleWrapperVersion
}

String defaultVersion = "default"


// Custom versioning scheme, take version of dependency with 'default' version from gradle.preperties
configurations.all {
resolutionStrategy.eachDependency { DependencyResolveDetails details ->
if (details.requested.version == defaultVersion) {
customer = property("plugin.default.customer")
String version = resolveDefaultVersion(details.requested.group, details.requested.name, customer)
details.useVersion(version)
}
}
}

configurations.all {
// check for updates every build
resolutionStrategy.cacheChangingModulesFor 0, 'seconds'
}



String resolveDefaultVersion(String group, String name, String customer) {
if(group == 'com.mycompany.domain' && name == 'custom-lib'){
String version = property("custom-lib.${customer}.version")
println "resolved artifact [$group.$name] version [$version]"
return version
}
}

sourceCompatibility = 1.8
targetCompatibility = 1.8

repositories {
mavenLocal()
mavenCentral()
maven { url "https://repo.grails.org/grails/core" }
add buildscript.repositories.getByName("remote-maven-repo")
}

dependencyManagement {
imports {
mavenBom "org.grails:grails-bom:$grailsVersion"
}
applyMavenExclusions false
}


dependencies {
provided 'org.springframework.boot:spring-boot-starter-logging'
provided "org.springframework.boot:spring-boot-starter-actuator"
provided "org.springframework.boot:spring-boot-autoconfigure"
provided "org.springframework.boot:spring-boot-starter-tomcat"

provided "org.grails:grails-web-boot"
provided "org.grails:grails-dependencies"
provided 'javax.servlet:javax.servlet-api:3.1.0'

testCompile "org.grails:grails-plugin-testing"

console "org.grails:grails-console"

//Security
compile "org.grails.plugins:spring-security-core:3.0.0.M1"
compile "org.grails.plugins:spring-security-acl:3.0.0.M1"
//Not grails3 compatible
//compile "org.grails.plugins:spring-security-oauth2-provider:2.0-RC5"

compile "org.grails.plugins:hibernate:4.3.10.6"
//configurable customer-dependent dependency, take version from gradle.properties
compile group: "com.mycompany.domain", name:"custom-lib", version:"$defaultVersion", changing: true
}

task wrapper(type: Wrapper) {
gradleVersion = gradleWrapperVersion
}

publishing {
publications {
mavenJava(MavenPublication) {
from components.java
// gradle can't handle custom versioning scheme and will left com.mycompany.domain.custom-lib version value as 'default' in generated pom, we will fix it here.
pom.withXml {
asNode().get('dependencies').get(0).get('dependency').each { dep ->
String pomVer = dep.get("version").text()
String pomArtifactId = dep.get("artifactId").text()
String pomGroupId = dep.get("groupId").text()
if(pomVer == defaultVersion){
String customer = property("plugin.default.customer")
dep.get("version").get(0).setValue(resolveDefaultVersion(pomGroupId, pomArtifactId, customer))
}else if (StringUtils.isEmpty(pomVer)){
//gradle also left dependencies with provided scope in pom without version --> remove these dependencies
dep.replaceNode {}
}
}
}
}
}
repositories {
maven {
name 'myArtifactory'
url "${artifactoryContextUrl}/${(project.version.endsWith('-SNAPSHOT') ? snapshotRepoKey : releaseRepoKey)}"
credentials {
username = artifactory_user
password = artifactory_password
}
}
}
}


install.repositories.mavenInstaller.pom.whenConfigured { pom ->
pom.dependencies.findAll { it.version == defaultVersion }.each { dep ->
dep.version = resolveDefaultVersion(dep.groupId, dep.artifactId, property("plugin.default.customer"))
}
}

当我运行 gradle install - 在本地 m2 存储库中安装插件一切正常,并且 pom 看起来不错,它具有完全相同的范围和版本的依赖项,还提供了在发布到本地存储库期间从 pom 中排除依赖项。当我运行 gradle publishMavenJavaPublicationToMyArtifactoryRepository pom 看起来很奇怪,gradle 忽略了构建脚本依赖范围中的定义,并且总是使用 runtime .举个例子:

pom after gradle install :
<dependency>
<groupId>org.grails.plugins</groupId>
<artifactId>spring-security-acl</artifactId>
<version>3.0.0.M1</version>
<scope>compile</scope>
</dependency>

pom after gradle publishMavenJavaPublicationToMyArtifactoryRepository :
<dependency>
<groupId>org.grails.plugins</groupId>
<artifactId>spring-security-acl</artifactId>
<version>3.0.0.M1</version>
<scope>runtime</scope>
</dependency>

gradle install 之后还有 pom不包含范围为 provided 的依赖项. gradle publishMavenJavaPublicationToMyArtifactoryRepository 之后的 Pom.xml包含
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>

没有版本,gradle 不喜欢那样。

为什么我会收到如此不同的结果?如何为 gradle publishMavenJavaPublicationToMyArtifactoryRepository 生成相同的 pom至于 gradle install .我不喜欢在出版物部分编辑 pom 的机会。非常感谢任何帮助。

最佳答案

这是孵化新的 maven-publish 的已知限制。插入。安装任务使用“旧”/稳定安装任务。如果你真的依赖这些范围,一种解决方法可能是使用基于 gradle 的“uploadArchives”任务,而不是依赖 bintray 插件来发布你的文件。或者,您可以使用新发布插件的 xml Hook 来实现修复。

关于maven - 将 grails3 插件发布到 Artifact - 生成的 pom 的差异,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33859584/

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