diff --git a/src/backend/turbo/build.gradle.kts b/src/backend/turbo/build.gradle.kts index 4d7989a4a..78caa1b20 100644 --- a/src/backend/turbo/build.gradle.kts +++ b/src/backend/turbo/build.gradle.kts @@ -1,15 +1,17 @@ import com.tencent.devops.utils.findPropertyOrEmpty + plugins { id("com.tencent.devops.boot") version "0.0.6" id("org.owasp.dependencycheck") version "7.1.0.1" kotlin("jvm") version "1.6.0" + nexusPublishing } allprojects { group = "com.tencent.bk.devops.turbo" version = (System.getProperty("turbo_version") ?: "0.0.2") + - if (System.getProperty("snapshot") == "true") "-SNAPSHOT" else "-RELEASE" + if (System.getProperty("snapshot") == "true") "-SNAPSHOT" else "" apply(plugin = "com.tencent.devops.boot") diff --git a/src/backend/turbo/buildSrc/build.gradle.kts b/src/backend/turbo/buildSrc/build.gradle.kts index 0663bd6a7..0cfcb9cfb 100644 --- a/src/backend/turbo/buildSrc/build.gradle.kts +++ b/src/backend/turbo/buildSrc/build.gradle.kts @@ -19,3 +19,7 @@ repositories { kotlinDslPluginOptions { experimentalWarning.set(false) } + +dependencies { + implementation("io.github.gradle-nexus.publish-plugin:io.github.gradle-nexus.publish-plugin.gradle.plugin:1.3.0") +} diff --git a/src/backend/turbo/buildSrc/src/main/kotlin/plugins/nexusPublishing.gradle.kts b/src/backend/turbo/buildSrc/src/main/kotlin/plugins/nexusPublishing.gradle.kts new file mode 100644 index 000000000..0554a0ff6 --- /dev/null +++ b/src/backend/turbo/buildSrc/src/main/kotlin/plugins/nexusPublishing.gradle.kts @@ -0,0 +1,17 @@ +import utils.MavenUtil + +plugins { + id("io.github.gradle-nexus.publish-plugin") +} + +nexusPublishing { + repositories { + sonatype { + nexusUrl.set(uri(MavenUtil.getUrl(project))) + snapshotRepositoryUrl.set(uri(MavenUtil.getUrl(project))) + + username.set(MavenUtil.getUserName(project)) + password.set(MavenUtil.getPassword(project)) + } + } +} diff --git a/src/backend/turbo/buildSrc/src/main/kotlin/plugins/task-deploy-to-maven.gradle.kts b/src/backend/turbo/buildSrc/src/main/kotlin/plugins/task-deploy-to-maven.gradle.kts index 8cb3b36cf..93a4426f0 100644 --- a/src/backend/turbo/buildSrc/src/main/kotlin/plugins/task-deploy-to-maven.gradle.kts +++ b/src/backend/turbo/buildSrc/src/main/kotlin/plugins/task-deploy-to-maven.gradle.kts @@ -25,11 +25,12 @@ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ import java.net.URI +import utils.MavenUtil plugins { `maven-publish` signing - maven +// `maven` java } @@ -97,76 +98,24 @@ publishing { developerConnection.set("scm:git:git@github.com:Tencent/bk-ci.git") } } + + versionMapping { + usage("java-api") { + fromResolutionOf("runtimeClasspath") + } + usage("java-runtime") { + fromResolutionResult() + } + } } } repositories { maven { name = "oss" - - // 正式包 - var mavenRepoDeployUrl = System.getProperty("mavenRepoDeployUrl") - var mavenRepoUsername = System.getProperty("mavenRepoUsername") - var mavenRepoPassword = System.getProperty("mavenRepoPassword") - - if (mavenRepoDeployUrl == null) { - mavenRepoDeployUrl = System.getenv("build_mavenRepoDeployUrl") - } - - if (mavenRepoUsername == null) { - mavenRepoUsername = System.getenv("build_mavenRepoUsername") - } - - if (mavenRepoPassword == null) { - mavenRepoPassword = System.getenv("build_mavenRepoPassword") - } - - if (mavenRepoDeployUrl == null) { - mavenRepoDeployUrl = project.extra["MAVEN_REPO_DEPLOY_URL"]?.toString() - } - - if (mavenRepoUsername == null) { - mavenRepoUsername = project.extra["MAVEN_REPO_USERNAME"]?.toString() - } - - if (mavenRepoPassword == null) { - mavenRepoPassword = project.extra["MAVEN_REPO_PASSWORD"]?.toString() - } - - // 快照包 - var snapshotMavenRepoDeployUrl = System.getProperty("snapshotMavenRepoDeployUrl") - var snapshotMavenRepoUsername = System.getProperty("snapshotMavenRepoUsername") - var snapshotMavenRepoPassword = System.getProperty("snapshotMavenRepoPassword") - - if (snapshotMavenRepoDeployUrl == null) { - snapshotMavenRepoDeployUrl = System.getenv("build_snapshotMavenRepoDeployUrl") - } - - if (snapshotMavenRepoUsername == null) { - snapshotMavenRepoUsername = System.getenv("build_snapshotMavenRepoUsername") - } - - if (snapshotMavenRepoPassword == null) { - snapshotMavenRepoPassword = System.getenv("build_snapshotMavenRepoPassword") - } - - if (snapshotMavenRepoDeployUrl == null) { - snapshotMavenRepoDeployUrl = project.extra["MAVEN_REPO_SNAPSHOT_DEPLOY_URL"]?.toString() - } - - if (snapshotMavenRepoUsername == null) { - snapshotMavenRepoUsername = project.extra["MAVEN_REPO_SNAPSHOT_USERNAME"]?.toString() - } - - if (snapshotMavenRepoPassword == null) { - snapshotMavenRepoPassword = project.extra["MAVEN_REPO_SNAPSHOT_PASSWORD"]?.toString() - } - - url = URI(if (System.getProperty("snapshot") == "true") snapshotMavenRepoDeployUrl else mavenRepoDeployUrl) + url = URI(MavenUtil.getUrl(project)) credentials { - username = - if (System.getProperty("snapshot") == "true") snapshotMavenRepoUsername else mavenRepoUsername - password = - if (System.getProperty("snapshot") == "true") snapshotMavenRepoPassword else mavenRepoPassword + username = MavenUtil.getUserName(project) + password = MavenUtil.getPassword(project) } } } @@ -176,111 +125,11 @@ signing { sign(publishing.publications["mavenJava"]) } -tasks.getByName("publish") { - onlyIf { - project.the()["main"].allSource.files.isNotEmpty() - } -} - -tasks.getByName("generateMetadataFileForMavenJavaPublication") { - onlyIf { - project.the()["main"].allSource.files.isNotEmpty() - } -} - -tasks.getByName("generatePomFileForMavenJavaPublication") { - onlyIf { - project.the()["main"].allSource.files.isNotEmpty() - } -} - -tasks.getByName("publishMavenJavaPublicationToOssRepository") { - onlyIf { - project.the()["main"].allSource.files.isNotEmpty() - } -} - -tasks.getByName("publishMavenJavaPublicationToMavenLocal") { - onlyIf { - project.the()["main"].allSource.files.isNotEmpty() - } -} - -tasks.getByName("publishToMavenLocal") { - onlyIf { - project.the()["main"].allSource.files.isNotEmpty() - } -} - -tasks.getByName("signMavenJavaPublication") { - onlyIf { - project.the()["main"].allSource.files.isNotEmpty() - } -} - -tasks.getByName("uploadArchives") { - var mavenRepoDeployUrl: String? = System.getProperty("mavenRepoDeployUrl") - var mavenRepoUsername = System.getProperty("mavenRepoUsername") - var mavenRepoPassword = System.getProperty("mavenRepoPassword") - - if (mavenRepoDeployUrl == null) { - mavenRepoDeployUrl = System.getenv("mavenRepoDeployUrl") - } - - if (mavenRepoUsername == null) { - mavenRepoUsername = System.getenv("mavenRepoUsername") - } - - if (mavenRepoPassword == null) { - mavenRepoPassword = System.getenv("mavenRepoPassword") - } - - if (mavenRepoDeployUrl == null) { - mavenRepoDeployUrl = project.extra["MAVEN_REPO_DEPLOY_URL"]?.toString() - } - - if (mavenRepoUsername == null) { - mavenRepoUsername = project.extra["MAVEN_REPO_USERNAME"]?.toString() - } - - if (mavenRepoPassword == null) { - mavenRepoPassword = project.extra["MAVEN_REPO_PASSWORD"]?.toString() - } - - // if snapshot repository is null - var snapshotRepositoryUrl = project.extra["MAVEN_REPO_SNAPSHOT_DEPLOY_URL"]?.toString() - var snapshotRepositoryUsername = project.extra["MAVEN_REPO_SNAPSHOT_USERNAME"]?.toString() - var snapshotRepositoryPassword = project.extra["MAVEN_REPO_SNAPSHOT_PASSWORD"]?.toString() - - if (snapshotRepositoryUrl == null || snapshotRepositoryUrl.isEmpty()) { - snapshotRepositoryUrl = System.getenv("snapshotMavenRepoDeployUrl") - } - if (snapshotRepositoryUsername == null || snapshotRepositoryUsername.isEmpty()) { - snapshotRepositoryUsername = System.getenv("snapshotMavenRepoUsername") - } - if (snapshotRepositoryPassword == null || snapshotRepositoryPassword.isEmpty()) { - snapshotRepositoryPassword = System.getenv("snapshotMavenRepoPassword") - } - - repositories.withGroovyBuilder { - "mavenDeployer" { - "repository"("url" to mavenRepoDeployUrl) { - "authentication"("userName" to mavenRepoUsername, "password" to mavenRepoPassword) - } - - "snapshotRepository"("url" to snapshotRepositoryUrl) { - "authentication"("userName" to snapshotRepositoryUsername, "password" to snapshotRepositoryPassword) - } - } - } - - onlyIf { - project.the()["main"].allSource.files.isNotEmpty() - } -} +val shouldPublish = project.the()["main"].allSource.files.isNotEmpty() || + project.name == "common-dependencies" -tasks.getByName("install") { - onlyIf { - project.the()["main"].allSource.files.isNotEmpty() +tasks.forEach { + if (it.group == "publishing") { + it.onlyIf { shouldPublish } } } diff --git a/src/backend/turbo/buildSrc/src/main/kotlin/utils/MavenUtil.kt b/src/backend/turbo/buildSrc/src/main/kotlin/utils/MavenUtil.kt new file mode 100644 index 000000000..0e246ea10 --- /dev/null +++ b/src/backend/turbo/buildSrc/src/main/kotlin/utils/MavenUtil.kt @@ -0,0 +1,43 @@ +package utils + +import org.gradle.api.Project +import org.gradle.kotlin.dsl.extra + +object MavenUtil { + + fun getUrl(project: Project): String { + return if (System.getProperty("snapshot") == "true") { + System.getProperty("snapshotMavenRepoDeployUrl") + ?: System.getenv("build_snapshotMavenRepoDeployUrl") + ?: project.extra["MAVEN_REPO_SNAPSHOT_DEPLOY_URL"]?.toString() + } else { + System.getProperty("mavenRepoDeployUrl") + ?: System.getenv("build_mavenRepoDeployUrl") + ?: project.extra["MAVEN_REPO_DEPLOY_URL"]?.toString() + } ?: "" + } + + fun getUserName(project: Project): String? { + return if (System.getProperty("snapshot") == "true") { + System.getProperty("snapshotMavenRepoUsername") + ?: System.getenv("build_snapshotMavenRepoUsername") + ?: project.extra["MAVEN_REPO_SNAPSHOT_USERNAME"]?.toString() + } else { + System.getProperty("mavenRepoUsername") + ?: System.getenv("build_mavenRepoUsername") + ?: project.extra["MAVEN_REPO_USERNAME"]?.toString() + } + } + + fun getPassword(project: Project): String? { + return if (System.getProperty("snapshot") == "true") { + System.getProperty("snapshotMavenRepoPassword") + ?: System.getenv("build_snapshotMavenRepoPassword") + ?: project.extra["MAVEN_REPO_SNAPSHOT_PASSWORD"]?.toString() + } else { + System.getProperty("mavenRepoPassword") + ?: System.getenv("build_mavenRepoPassword") + ?: project.extra["MAVEN_REPO_PASSWORD"]?.toString() + } + } +} diff --git a/src/backend/turbo/gradle/wrapper/gradle-wrapper.properties b/src/backend/turbo/gradle/wrapper/gradle-wrapper.properties index 442d9132e..f371643ee 100644 --- a/src/backend/turbo/gradle/wrapper/gradle-wrapper.properties +++ b/src/backend/turbo/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-6.8.3-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.0-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists