'Convert to gradle-kotlin-dsl Jfrog.Artifactory config
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)
}
}
}
}
}
Solution 1:[1]
I found another example - an official one JFrog:
import org.jfrog.gradle.plugin.artifactory.task.ArtifactoryTask
buildscript {
repositories {
mavenLocal()
mavenCentral()
}
dependencies {
classpath("org.jfrog.buildinfo", "build-info-extractor-gradle", "4.+")
}
configurations.classpath {
resolutionStrategy {
cacheDynamicVersionsFor(0, "seconds")
cacheChangingModulesFor(0, "seconds")
}
}
}
plugins {
java
`maven-publish`
}
fun javaProjects() = subprojects.filter {
File(it.projectDir, "src").isDirectory
}
val currentVersion: String by project
allprojects {
apply(plugin = "com.jfrog.artifactory")
group = "org.jfrog.test.gradle.publish"
version = currentVersion
status = "Integration"
repositories {
maven("http://127.0.0.1:8081/artifactory/libs-release")
}
}
tasks.named<ArtifactoryTask>("artifactoryPublish") {
skip = true
}
project("services") {
tasks.named<ArtifactoryTask>("artifactoryPublish") {
skip = true
}
}
configure(javaProjects()) {
apply(plugin = "java")
apply(plugin = "maven-publish")
dependencies {
testImplementation("junit:junit:4.7")
}
configure<PublishingExtension> {
publications {
register<MavenPublication>("mavenJava") {
from(components.getByName("java"))
artifact(file("$rootDir/gradle.properties"))
}
}
}
}
project("api") {
apply(plugin = "ivy-publish")
configure<PublishingExtension> {
publications {
register<IvyPublication>("ivyJava") {
from(components.getByName("java"))
artifact(file("$rootDir/settings.gradle.kts")) {
name = "gradle-settings"
extension = "txt"
type = "text"
}
// The config below will add a extra attribute to the ivy.xml
// See http://ant.apache.org/ivy/history/latest-milestone/concept.html#extra
descriptor.withXml {
val info = asNode().get("info") as groovy.util.NodeList
val first = info.first() as groovy.util.Node
first.attributes()["e:architecture"] = "amd64"
}
}
}
}
tasks.named<ArtifactoryTask>("artifactoryPublish") {
publications(publishing.publications["ivyJava"])
}
}
configure<org.jfrog.gradle.plugin.artifactory.dsl.ArtifactoryPluginConvention> {
clientConfig.isIncludeEnvVars = true
setContextUrl("http://127.0.0.1:8081/artifactory")
publish {
repository {
setRepoKey("libs-snapshot-local") // The Artifactory repository key to publish to
setUsername(findProperty("artifactory_user")) // The publisher user name
setPassword(findProperty("artifactory_password")) // The publisher password
// This is an optional section for configuring Ivy publication (when publishIvy = true).
ivy {
setIvyLayout("[organization]/[module]/ivy-[revision].xml")
setArtifactLayout("[organization]/[module]/[revision]/[module]-[revision](-[classifier]).[ext]")
setMavenCompatible(true) // Convert any dots in an [organization] layout value to path separators, similar to Maven"s groupId-to-path conversion. True if not specified
}
}
defaults {
// Reference to Gradle publications defined in the build script.
// This is how we tell the Artifactory Plugin which artifacts should be
// published to Artifactory.
publications("mavenJava")
setPublishArtifacts(true)
// Properties to be attached to the published artifacts.
setProperties(mapOf(
"qa.level" to "basic",
"dev.team" to "core"
))
setPublishPom(true) // Publish generated POM files to Artifactory (true by default)
setPublishIvy(true) // Publish generated Ivy descriptor files to Artifactory (true by default)
}
}
}
Solution 2:[2]
The accepted answer didn't work for me with the artifactory plugin version 4.27.1. A good place to check is definitely the already mentioned provided example by JFrog. Here is a simplified extract based on the offical example:
configure<org.jfrog.gradle.plugin.artifactory.dsl.ArtifactoryPluginConvention> {
clientConfig.isIncludeEnvVars = true
setContextUrl(findProperty("artifactory_url"))
publish {
repository {
setRepoKey(repoKeyValue) // The Artifactory repository key to publish to
setUsername(findProperty("artifactory_user")) // The publisher user name
setPassword(findProperty("artifactory_password")) // The publisher password
setMavenCompatible(true)
}
defaults {
publications("mypublicationreference")
setPublishArtifacts(true)
}
}
}
configure<PublishingExtension> {
publications {
register<MavenPublication>("mypublicationreference") {
from(components.getByName("java"))
artifact("$buildDir/libs/${project.name}.jar")
}
}
}
Note that the referenced properties such as artifactory_url can be defined in a gradle.properties file.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Alexander Taylor |
| Solution 2 | 34m0 |
