我正试图从groovy迁移到gradle-kotlin dsl,但是我是新手,所以我不知道如何配置Jfrog Artifactory。请帮助我将那部分代码转换为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)
}
}
}
}
}
答案 0 :(得分:1)
我这样解决了:
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")
})