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'
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 {
'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
]
}
}
- if (System.getenv('GITHUB_BRANCH') == "branch-nightly-build") {
+ if (isNightlyBuild) {
tasks.withType(Test) {
configurations {
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")
}
}
}
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) {
mavenJava(MavenPublication) {
artifact zip
}
- mavenJava(MavenPublication) {
- artifact bomArtifact
+ if (enableBom) {
+ mavenJava(MavenPublication) {
+ artifact bomArtifact
+ }
}
}
}