首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何将gradle中的groovy任务转换为Gradle Kotlin DSL以生成pom.xml?

如何将gradle中的groovy任务转换为Gradle Kotlin DSL以生成pom.xml?
EN

Stack Overflow用户
提问于 2018-01-30 12:59:02
回答 1查看 651关注 0票数 2

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

代码语言:javascript
运行
复制
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

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-01-30 19:16:30

我相信这和build.gradle.kts文件是一样的:

代码语言:javascript
运行
复制
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方法将非类型化属性添加到模型中

票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/48514138

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档