Skip to content

Commit 9243aed

Browse files
authored
SONARGO-82 Split artifactory configuration into artifactory and publishing (#10)
1 parent 46a3607 commit 9243aed

3 files changed

Lines changed: 100 additions & 64 deletions

File tree

gradle-modules/src/main/kotlin/org.sonarsource.cloud-native.artifactory-configuration.gradle.kts

Lines changed: 6 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -15,73 +15,22 @@
1515
* along with this program; if not, see https://sonarsource.com/license/ssal/
1616
*/
1717
import org.sonarsource.cloudnative.gradle.ArtifactoryConfiguration
18-
import org.sonarsource.cloudnative.gradle.signingCondition
1918

2019
plugins {
21-
id("com.jfrog.artifactory")
22-
signing
20+
// `maven-publish` is required for the `artifactory` plugin (or the root project shoudn't be published)
2321
`maven-publish`
22+
id("com.jfrog.artifactory")
23+
}
24+
25+
if (project.path != ":") {
26+
throw GradleException("This build script must be applied to the root project only")
2427
}
2528

2629
// this value is present on CI
2730
val buildNumber: String? = System.getProperty("buildNumber")
28-
if (project.version.toString().endsWith("-SNAPSHOT") && buildNumber != null) {
29-
val versionSuffix = if (project.version.toString().count { it == '.' } == 1) ".0.$buildNumber" else ".$buildNumber"
30-
project.version = project.version.toString().replace("-SNAPSHOT", versionSuffix)
31-
logger.lifecycle("Project version set to $version")
32-
}
3331

3432
val artifactoryConfiguration = extensions.create<ArtifactoryConfiguration>("artifactoryConfiguration")
3533

36-
publishing {
37-
publications.create<MavenPublication>("mavenJava") {
38-
pom {
39-
name = artifactoryConfiguration.pomName
40-
description = project.description
41-
url = "http://www.sonarqube.org/"
42-
organization {
43-
name = "SonarSource"
44-
url = "http://www.sonarsource.com/"
45-
}
46-
licenses {
47-
license {
48-
name = artifactoryConfiguration.license.name
49-
url = artifactoryConfiguration.license.url
50-
distribution = artifactoryConfiguration.license.distribution
51-
comments = artifactoryConfiguration.license.comments
52-
}
53-
}
54-
scm {
55-
url = artifactoryConfiguration.scmUrl
56-
}
57-
developers {
58-
developer {
59-
id = "sonarsource-team"
60-
name = "SonarSource Team"
61-
}
62-
}
63-
}
64-
}
65-
}
66-
67-
signing {
68-
val signingKeyId: String? by project
69-
val signingKey: String? by project
70-
val signingPassword: String? by project
71-
useInMemoryPgpKeys(signingKeyId, signingKey, signingPassword)
72-
setRequired {
73-
project.signingCondition()
74-
}
75-
sign(publishing.publications)
76-
}
77-
78-
tasks.withType<Sign> {
79-
onlyIf {
80-
val artifactorySkip: Boolean = tasks.artifactoryPublish.get().skip
81-
!artifactorySkip && project.signingCondition()
82-
}
83-
}
84-
8534
// `afterEvaluate` is required to inject configurable properties; see https://github.com/jfrog/artifactory-gradle-plugin/issues/71#issuecomment-1734977528
8635
project.afterEvaluate {
8736
artifactory {
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
/*
2+
* SonarSource Cloud Native Gradle Modules
3+
* Copyright (C) 2024-2024 SonarSource SA
4+
* mailto:info AT sonarsource DOT com
5+
*
6+
* This program is free software; you can redistribute it and/or
7+
* modify it under the terms of the Sonar Source-Available License Version 1, as published by SonarSource SA.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12+
* See the Sonar Source-Available License for more details.
13+
*
14+
* You should have received a copy of the Sonar Source-Available License
15+
* along with this program; if not, see https://sonarsource.com/license/ssal/
16+
*/
17+
import org.gradle.kotlin.dsl.create
18+
import org.jfrog.gradle.plugin.artifactory.task.ArtifactoryTask
19+
import org.sonarsource.cloudnative.gradle.PublishingConfiguration
20+
import org.sonarsource.cloudnative.gradle.signingCondition
21+
22+
plugins {
23+
signing
24+
`maven-publish`
25+
// Connection to artifactory is configured from the root project; applying it here enables publishing of this project
26+
id("com.jfrog.artifactory")
27+
}
28+
29+
val publishingConfiguration = extensions.create<PublishingConfiguration>("publishingConfiguration")
30+
31+
publishing {
32+
publications.create<MavenPublication>("mavenJava") {
33+
pom {
34+
name = publishingConfiguration.pomName
35+
description = project.description
36+
url = "http://www.sonarqube.org/"
37+
organization {
38+
name = "SonarSource"
39+
url = "http://www.sonarsource.com/"
40+
}
41+
licenses {
42+
license {
43+
name = publishingConfiguration.license.name
44+
url = publishingConfiguration.license.url
45+
distribution = publishingConfiguration.license.distribution
46+
comments = publishingConfiguration.license.comments
47+
}
48+
}
49+
scm {
50+
url = publishingConfiguration.scmUrl
51+
}
52+
developers {
53+
developer {
54+
id = "sonarsource-team"
55+
name = "SonarSource Team"
56+
}
57+
}
58+
}
59+
}
60+
}
61+
62+
signing {
63+
val signingKeyId: String? by project
64+
val signingKey: String? by project
65+
val signingPassword: String? by project
66+
useInMemoryPgpKeys(signingKeyId, signingKey, signingPassword)
67+
setRequired {
68+
project.signingCondition()
69+
}
70+
sign(publishing.publications)
71+
}
72+
73+
tasks.withType<Sign> {
74+
onlyIf {
75+
val artifactorySkip: Boolean = tasks.named<ArtifactoryTask>("artifactoryPublish").map { it.skip }.getOrElse(true)
76+
!artifactorySkip && project.signingCondition()
77+
}
78+
}

gradle-modules/src/main/kotlin/org/sonarsource/cloudnative/gradle/ArtifactoryConfiguration.kt

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,29 @@ import org.gradle.api.publish.maven.MavenPomLicense
2222
import org.gradle.kotlin.dsl.newInstance
2323
import org.gradle.kotlin.dsl.property
2424

25-
open class ArtifactoryConfiguration(
25+
/**
26+
* Settings for publication of the project
27+
*/
28+
open class PublishingConfiguration(
2629
objects: ObjectFactory,
2730
) {
2831
val pomName: Property<String> = objects.property()
29-
val buildName: Property<String> = objects.property()
3032
val scmUrl: Property<String> = objects.property()
31-
val artifactsToPublish: Property<String> = objects.property()
32-
val artifactsToDownload: Property<String> = objects.property()
33-
val repoKeyEnv: Property<String> = objects.property()
34-
val usernameEnv: Property<String> = objects.property()
35-
val passwordEnv: Property<String> = objects.property()
3633
internal val license: MavenPomLicense = objects.newInstance()
3734

3835
fun license(action: MavenPomLicense.() -> Unit) {
3936
action.invoke(license)
4037
}
4138
}
39+
40+
/**
41+
* Settings for connection to Artifactory
42+
*/
43+
interface ArtifactoryConfiguration {
44+
val buildName: Property<String>
45+
val artifactsToPublish: Property<String>
46+
val artifactsToDownload: Property<String>
47+
val repoKeyEnv: Property<String>
48+
val usernameEnv: Property<String>
49+
val passwordEnv: Property<String>
50+
}

0 commit comments

Comments
 (0)