本文介绍了转换为gradle-kotlin-dsl Jfrog.Artifactory配置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正试图从groovy迁移到gradle-kotlin dsl,但是我是新手,所以我不知道如何配置Jfrog Artifactory.请帮助我将那部分代码转换为gradle-kotlin dsl:

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)
                }
            }
        }
    }
}

推荐答案

我是这样解决的:

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")
    })

这篇关于转换为gradle-kotlin-dsl Jfrog.Artifactory配置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-05 20:30