问题
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