gpt4 book ai didi

maven - 从 gradle 导出 Maven pom.xml 文件时注入(inject)构建 block 时遇到问题

转载 作者:行者123 更新时间:2023-12-03 04:46:57 24 4
gpt4 key购买 nike

task writeNewPom {
pom {
project {
/*
build {
plugins {
plugin {
groupId 'GROUP_ID'
artifactId 'maven-ipcentral-plugin'
version '4.7'
executions {}
configuration {
url "http://CENTRAL_REPORTING_SERVER"
logfileprefix "test"
ipcProject = true
businessUnit "FOUR_DIGIT_CODE"
componentEditorsGrouper "ccp-dev"
assetEditorsGrouper "ccp-dev"
username "USERNAME"
}
}
}
}
*/
pluginRepositories {
pluginRepository {
id 'ipcentral-snapshots'
name 'IPCentral Snapshot Repository'
url 'http://PLUGIN_SOURCE/'
snapshots {
enabled = false
}
releases {
enabled = true
}
}
}

profiles {
profile {
id 'inject-cec-credentials'
activation {
activeByDefault = true
}
properties {
username = "USERNAME"
}
}
}
}
}.writeTo("ipcentral/pom.xml")
}

我正在尝试使用 gradle maven 插件创建一个 pom.xml 文件。它必须引用为中央依赖报告设计的 Maven 插件。现在它成功创建了包含所有依赖项、插件存储库信息和配置文件信息的 pom.xml 文件。但是,如果未注释构建部分,则会出现以下错误:
> No such property: _SCRIPT_CLASS_NAME_ for class: org.apache.maven.model.

如果我尝试一些简单的事情,比如
task writeNewPom {
pom {
project {
build {
}
}
}
}

然后我得到同样的错误。似乎 gradle 无法将 build 识别为有效标识符。我只是希望有一个比通过 groovy 手动编辑 xml 更优雅的解决方案。我能找到的唯一文档是 Gradle docs Chap 53

最佳答案

这是因为 project {...}闭包委托(delegate)给 ModelBuilder 的一个实例它扩展了 Groovy 的 FactoryBuilderSupport已经定义了一个名为 build 的方法的类.所以不要配置 build Maven 的属性(property) Model对象,预先存在的build方法被调用。

为了解决这个问题,我会使用 withXml {...}配置你的 pom 的那部分。

pom {
project {
// other non-<build> configuration
}
}.withXml {
asNode().appendNode('build').appendNode('plugins').appendNode('plugin').with {
appendNode('groupId', 'GROUP_ID')
}
}.writeTo('pom.xml')

关于maven - 从 gradle 导出 Maven pom.xml 文件时注入(inject)构建 block 时遇到问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27975786/

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