Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/backend/turbo/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -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")

Expand Down
4 changes: 4 additions & 0 deletions src/backend/turbo/buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Original file line number Diff line number Diff line change
@@ -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))
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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)
}
}
}
Expand All @@ -176,111 +125,11 @@ signing {
sign(publishing.publications["mavenJava"])
}

tasks.getByName("publish") {
onlyIf {
project.the<SourceSetContainer>()["main"].allSource.files.isNotEmpty()
}
}

tasks.getByName("generateMetadataFileForMavenJavaPublication") {
onlyIf {
project.the<SourceSetContainer>()["main"].allSource.files.isNotEmpty()
}
}

tasks.getByName("generatePomFileForMavenJavaPublication") {
onlyIf {
project.the<SourceSetContainer>()["main"].allSource.files.isNotEmpty()
}
}

tasks.getByName("publishMavenJavaPublicationToOssRepository") {
onlyIf {
project.the<SourceSetContainer>()["main"].allSource.files.isNotEmpty()
}
}

tasks.getByName("publishMavenJavaPublicationToMavenLocal") {
onlyIf {
project.the<SourceSetContainer>()["main"].allSource.files.isNotEmpty()
}
}

tasks.getByName("publishToMavenLocal") {
onlyIf {
project.the<SourceSetContainer>()["main"].allSource.files.isNotEmpty()
}
}

tasks.getByName("signMavenJavaPublication") {
onlyIf {
project.the<SourceSetContainer>()["main"].allSource.files.isNotEmpty()
}
}

tasks.getByName<Upload>("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<SourceSetContainer>()["main"].allSource.files.isNotEmpty()
}
}
val shouldPublish = project.the<SourceSetContainer>()["main"].allSource.files.isNotEmpty() ||
project.name == "common-dependencies"

tasks.getByName("install") {
onlyIf {
project.the<SourceSetContainer>()["main"].allSource.files.isNotEmpty()
tasks.forEach {
if (it.group == "publishing") {
it.onlyIf { shouldPublish }
}
}
43 changes: 43 additions & 0 deletions src/backend/turbo/buildSrc/src/main/kotlin/utils/MavenUtil.kt
Original file line number Diff line number Diff line change
@@ -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()
}
}
}
2 changes: 1 addition & 1 deletion src/backend/turbo/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -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