gpt4 book ai didi

maven - 如何将gradle中的常规任务转换为Gradle Kotlin DSL以生成pom.xml?

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

以下Gradle脚本的build.gradle.kts版本是什么?

apply plugin: 'maven'
apply plugin: 'java'

sourceCompatibility = 7
targetCompatibility = 7

dependencies {
compile 'com.google.guava:guava:13.0.1'
compile 'joda-time:joda-time:2.1'

testCompile 'junit:junit:4.11'
testCompile 'org.mockito:mockito-core:1.9.5'
}

task writeNewPom << {
pom {
project {
groupId 'org.example'
artifactId 'test'
version '1.0.0'

inceptionYear '2008'
licenses {
license {
name 'The Apache Software License, Version 2.0'
url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
distribution 'repo'
}
}
}
}.writeTo("$buildDir/newpom.xml")
}

引用文献

1- Gradle样本为 here

最佳答案

我相信这与build.gradle.kts文件相同:

plugins {
java
maven
}

java {
sourceCompatibility = JavaVersion.VERSION_1_7
targetCompatibility = JavaVersion.VERSION_1_7
}

repositories {
jcenter()
}

dependencies {
compile("com.google.guava:guava:13.0.1")
compile("joda-time:joda-time:2.1")

testCompile("junit:junit:4.11")
testCompile("org.mockito:mockito-core:1.9.5")
}

tasks {
"writeNewPom" {
doLast {
project.the<MavenPluginConvention>().pom {
project {
groupId = "org.example"
artifactId = "test"
version = "1.0.0"
withGroovyBuilder {
"inceptionYear"("2008")
"licenses" {
"license" {
"name"("The Apache Software License, Version 2.0")
"url"("http://www.apache.org/licenses/LICENSE-2.0.txt")
"distribution"("repo")
}
}
}
}
}.writeTo("$buildDir/newPom.xml")
}
}
}

您必须使用 withGroovyBuilder方法将未类型化的属性添加到模型中

关于maven - 如何将gradle中的常规任务转换为Gradle Kotlin DSL以生成pom.xml?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48514138/

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