From 1ea0fba721acca7bfbdbed82cdeaf779e39ca85f Mon Sep 17 00:00:00 2001 From: Julien Carsique Date: Fri, 2 Sep 2022 17:55:10 +0200 Subject: BUILD-1745 execute only on CI and main branch or explicit call fix: remove sonar-web from bom inputs.files, a dedicated yarn bom build is to be implemented if needed --- build.gradle | 35 ++++++++++++++++++++++++++--------- sonar-application/build.gradle | 8 +++++--- 2 files changed, 31 insertions(+), 12 deletions(-) diff --git a/build.gradle b/build.gradle index 5ae2fa30754..e353e1501b3 100644 --- a/build.gradle +++ b/build.gradle @@ -17,6 +17,20 @@ if (!JavaVersion.current().java11Compatible) { throw new GradleException("JDK 11+ is required to perform this build. It's currently " + System.getProperty("java.home") + ".") } +/** + * The BOM related tasks are disabled by default, activated by: + * - running in the CI and being on a main branch or a nightly build, + * - or using '-Dbom' project property + * - or by explicit call to 'cyclonedxBom' Gradle task + */ +def bomTasks = "cyclonedxBom" +def ghBranch = System.getenv()["GITHUB_BRANCH"] +def isMainBranch = ghBranch in ['master'] || ghBranch ==~ 'branch-[\\d.]+' +def isNightlyBuild = ghBranch == "branch-nightly-build" +boolean enableBom = System.getenv('CI') == "true" && (isMainBranch || isNightlyBuild) || + System.getProperty("bom") != null || + gradle.startParameter.taskNames.findAll({ it.matches(".*:($bomTasks)") }) + allprojects { apply plugin: 'com.jfrog.artifactory' apply plugin: 'maven-publish' @@ -37,6 +51,14 @@ allprojects { official = project.hasProperty('official') && project.getProperty('official') } + ext.enableBom = enableBom + if (!enableBom) { + tasks.matching { it.name.matches(bomTasks) }.all({ + logger.info("{} disabled", it.name); + it.enabled = false + }) + } + repositories { def repository = project.hasProperty('qa') ? 'sonarsource-qa' : 'sonarsource' maven { @@ -78,7 +100,7 @@ allprojects { 'build.number': System.getenv('BUILD_NUMBER'), 'pr.branch.target': System.getenv('GITHUB_BASE_BRANCH'), 'pr.number': System.getenv('PULL_REQUEST'), - 'vcs.branch': System.getenv('GITHUB_BRANCH'), + 'vcs.branch': ghBranch, 'vcs.revision': System.getenv('GIT_SHA1'), 'version': version ] @@ -507,7 +529,7 @@ subprojects { } } - if (System.getenv('GITHUB_BRANCH') == "branch-nightly-build") { + if (isNightlyBuild) { tasks.withType(Test) { configurations { @@ -536,19 +558,14 @@ subprojects { def signingPassword = findProperty("signingPassword") useInMemoryPgpKeys(signingKeyId, signingKey, signingPassword) required { - def branch = System.getenv()["GITHUB_BRANCH"] - return (branch in ['master'] || branch ==~ 'branch-[\\d.]+') && - gradle.taskGraph.hasTask(":artifactoryPublish") + return isMainBranch && gradle.taskGraph.hasTask(":artifactoryPublish") } sign publishing.publications } tasks.withType(Sign) { onlyIf { - def branch = System.getenv()["GITHUB_BRANCH"] - return !artifactoryPublish.skip && - (branch in ['master'] || branch ==~ 'branch-[\\d.]+') && - gradle.taskGraph.hasTask(":artifactoryPublish") + return !artifactoryPublish.skip && isMainBranch && gradle.taskGraph.hasTask(":artifactoryPublish") } } } diff --git a/sonar-application/build.gradle b/sonar-application/build.gradle index 59f09a9d780..9f24ddbccd3 100644 --- a/sonar-application/build.gradle +++ b/sonar-application/build.gradle @@ -340,7 +340,7 @@ cyclonedxBom { outputs.file bomFile } tasks.cyclonedxBom { - inputs.files(configurations.runtimeClasspath, configurations.web, configurations.shutdowner, configurations.jdbc_mssql, + inputs.files(configurations.runtimeClasspath, configurations.shutdowner, configurations.jdbc_mssql, configurations.jdbc_postgresql, configurations.jdbc_h2, configurations.bundledPlugin_deps, configurations.cyclonedx) } def bomArtifact = artifacts.add('archives', bomFile.get().asFile) { @@ -354,8 +354,10 @@ publishing { mavenJava(MavenPublication) { artifact zip } - mavenJava(MavenPublication) { - artifact bomArtifact + if (enableBom) { + mavenJava(MavenPublication) { + artifact bomArtifact + } } } } -- cgit v1.2.3