Convert to gradle-kotlin-dsl Jfrog.Artifactory config

≡放荡痞女 提交于 2021-01-24 09:19:16

问题


I'm trying to migrate from groovy to gradle-kotlin dsl, but I'm new to it, so I dont know how to configure Jfrog Artifactory. Please help me with converting that part of code to gradle-kotlin dsl:

task sourceJar(type: Jar) {
    from sourceSets.main.allJava
}

artifactory {
    contextUrl = "http://10.0.0.49:8081/artifactory"
    publish {
        repository {
            repoKey = 'gradle-dev-local'
            username = artifactory_username
            password = artifactory_password
        }
        defaults {
            publications('mavenJava')
            publishArtifacts = true
            publishPom = true
        }
    }
}



publishing {
    publications {
        mavenJava(MavenPublication) {
            groupId = "ua.tiras.oloader"
            artifactId = 'core'
            version = "1.0.62"
            artifact("$buildDir/libs/${project.getName()}.jar")
            artifact sourceJar {
                classifier "sources"
            }
            pom.withXml {
                def dependenciesNode = asNode().appendNode('dependencies')
                configurations.api.allDependencies.each { dependency ->
                    def dependencyNode = dependenciesNode.appendNode('dependency')
                    dependencyNode.appendNode('groupId', dependency.group)
                    dependencyNode.appendNode('artifactId', dependency.name)
                    dependencyNode.appendNode('version', dependency.version)
                }
            }
        }
    }
}

回答1:


I solved it this way:

val sourcesJar by tasks.creating(Jar::class) {
    dependsOn(JavaPlugin.CLASSES_TASK_NAME)
    classifier = "sources"
    from(sourceSets["main"].allSource)
}

publishing {
    publications {
        create<MavenPublication>("mavenJava") {
            groupId = "ua.tiras"
            artifactId = "aloader-core"
            version = "0.0.4"

            artifact(sourcesJar)
            artifact("$buildDir/libs/${project.name}.jar")

            pom {
                withXml {
                    asNode().appendNode("dependencies").let {
                        for (dependency in configurations["api"].dependencies) {
                            it.appendNode("dependency").apply {
                                appendNode("groupId", dependency.group)
                                appendNode("artifactId", dependency.name)
                                appendNode("version", dependency.version)
                            }
                        }
                    }
                }
            }
        }
    }
}

artifactory {
    setContextUrl("http://dev.tirascloud.com:8081/artifactory")
    publish(delegateClosureOf<PublisherConfig> {
        repository(delegateClosureOf<GroovyObject> {
            setProperty("repoKey", "gradle-dev-local")
            setProperty("username", project.findProperty("artifactory_username") ?: "nouser")
            setProperty("password", project.findProperty("artifactory_password") ?: "nopass")
        })
        defaults(delegateClosureOf<GroovyObject> {
            invokeMethod("publications", "mavenJava")
            setProperty("publishPom", true)
            setProperty("publishArtifacts", true)
        })
    })
    resolve(delegateClosureOf<ResolverConfig> {
        setProperty("repoKey", "repo")
    })


来源:https://stackoverflow.com/questions/56128767/convert-to-gradle-kotlin-dsl-jfrog-artifactory-config

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!