From 09979e2fde9b92aa7bc00de4175a88d64fe9e33f Mon Sep 17 00:00:00 2001 From: Jessica Wagantall Date: Tue, 25 Aug 2020 15:15:42 -0700 Subject: [PATCH] Run Sonar scans using JDK11. java-version will only set java for the maven build part of the job, the sonar scan will use sonarcloud-java-version which is set to openjdk11. Projects not compatible with JDK11 will be able to run their build with java-version set to their JDK preference. https://sonarcloud.io/documentation/user-guide/move-analysis-java-11/ Issue: RELENG-3176 Signed-off-by: Jessica Wagantall Change-Id: Ida96043317da7671034416df6a438350041f4731 --- docs/jjb/lf-maven-jobs.rst | 6 ++++-- jjb/lf-maven-jobs.yaml | 5 +++++ jjb/lf-python-jobs.yaml | 4 ++++ .../notes/maven-sonar-jdk-override-d73c9d6436dfacae.yaml | 9 +++++++++ shell/maven-sonar.sh | 6 ++++++ 5 files changed, 28 insertions(+), 2 deletions(-) create mode 100644 releasenotes/notes/maven-sonar-jdk-override-d73c9d6436dfacae.yaml diff --git a/docs/jjb/lf-maven-jobs.rst b/docs/jjb/lf-maven-jobs.rst index 3b3676c2..0ce612e2 100644 --- a/docs/jjb/lf-maven-jobs.rst +++ b/docs/jjb/lf-maven-jobs.rst @@ -34,12 +34,13 @@ Runs Sonar against a Maven project and pushes results to SonarCloud. :Required Parameters: - :java-version: Version of Java to execute Sonar with. + :java-version: Version of Java to execute Maven build. (default: openjdk8) :mvn-version: Version of Maven to execute Sonar with. :mvn-settings: Maven settings.xml file containing credentials to use. :sonarcloud-project-key: SonarCloud project key. :sonarcloud-project-organization: SonarCloud project organization. :sonarcloud-api-token: SonarCloud API Token. + :sonarcloud-java-version: Version of Java to run the Sonar scan. lf-maven-build -------------- @@ -484,7 +485,7 @@ multi-branch configuration. one may want to provide more than 1 cron timer. (default: 'H H * * 6' to run weekly) :git-url: URL clone project from. (default: $GIT_URL/$PROJECT) - :java-version: Version of Java to use for the build. (default: openjdk8) + :java-version: Version of Java to use for the Maven build. (default: openjdk8) :mvn-global-settings: The name of the Maven global settings to use for Maven configuration. (default: global-settings) :mvn-goals: The maven goals to perform for the build. @@ -500,6 +501,7 @@ multi-branch configuration. :sonarcloud-project-organization: SonarCloud project organization. (default: '') :sonarcloud-api-token: SonarCloud API Token. (default: '') + :sonarcloud-java-version: Version of Java to use for the Sonar scan. (default: openjdk11) :stream: Keyword that represents a release code-name. Often the same as the branch. (default: master) :submodule-recursive: Whether to checkout submodules recursively. diff --git a/jjb/lf-maven-jobs.yaml b/jjb/lf-maven-jobs.yaml index d13bb5d3..9bf175c3 100644 --- a/jjb/lf-maven-jobs.yaml +++ b/jjb/lf-maven-jobs.yaml @@ -1138,6 +1138,9 @@ sonarcloud-project-key: "" sonarcloud-project-organization: "" sonarcloud-api-token: "" + # SonarCloud scan using jdk8 will become deprecated by Oct, 2020 + # Projects not compatible with jdk11 can set java-version to something else + sonarcloud-java-version: openjdk11 stream: master submodule-recursive: true submodule-timeout: 10 @@ -1212,6 +1215,7 @@ sonarcloud-project-key: "{sonarcloud-project-key}" sonarcloud-project-organization: "{sonarcloud-project-organization}" sonarcloud-api-token: "{sonarcloud-api-token}" + sonarcloud-java-version: "{sonarcloud-java-version}" # With SonarQube - conditional-step: condition-kind: not @@ -1268,6 +1272,7 @@ PROJECT_ORGANIZATION={sonarcloud-project-organization} MAVEN_GOALS={mvn-goals} API_TOKEN={sonarcloud-api-token} + SONARCLOUD_JAVA_VERSION={sonarcloud-java-version} - lf-provide-maven-settings: global-settings-file: global-settings settings-file: "{mvn-settings}" diff --git a/jjb/lf-python-jobs.yaml b/jjb/lf-python-jobs.yaml index c29dd5d8..8d3c8855 100644 --- a/jjb/lf-python-jobs.yaml +++ b/jjb/lf-python-jobs.yaml @@ -255,6 +255,9 @@ sonarcloud-project-key: "" sonarcloud-project-organization: "" sonarcloud-api-token: "" + # SonarCloud scan using jdk8 will become deprecated by Oct, 2020 + # Projects not compatible with jdk11 can set java-version to something else + sonarcloud-java-version: openjdk11 stream: master submodule-recursive: true submodule-timeout: 10 @@ -332,6 +335,7 @@ # yamllint disable-line rule:line-length sonarcloud-project-organization: "{sonarcloud-project-organization}" sonarcloud-api-token: "{sonarcloud-api-token}" + sonarcloud-java-version: "{sonarcloud-java-version}" # With SonarQube - conditional-step: condition-kind: not diff --git a/releasenotes/notes/maven-sonar-jdk-override-d73c9d6436dfacae.yaml b/releasenotes/notes/maven-sonar-jdk-override-d73c9d6436dfacae.yaml new file mode 100644 index 00000000..023613e0 --- /dev/null +++ b/releasenotes/notes/maven-sonar-jdk-override-d73c9d6436dfacae.yaml @@ -0,0 +1,9 @@ +--- +fixes: + - | + Run Sonar scans using JDK11. + *java-version* will only set java for the maven build part of the job, + the sonar scan will use *sonarcloud-java-version* which is set to *openjdk11*. + Projects not compatible with JDK11 will be able to run their build with + *java-version* set to their JDK preference. + https://sonarcloud.io/documentation/user-guide/move-analysis-java-11/ diff --git a/shell/maven-sonar.sh b/shell/maven-sonar.sh index d370748b..9e00d218 100644 --- a/shell/maven-sonar.sh +++ b/shell/maven-sonar.sh @@ -36,6 +36,12 @@ if [ "$SONAR_HOST_URL" = "https://sonarcloud.io" ]; then params+=("-Dsonar.login=$API_TOKEN") fi +if [ "$SET_JDK_VERSION" != "$SONARCLOUD_JAVA_VERSION" ]; then + export SET_JDK_VERSION="$SONARCLOUD_JAVA_VERSION" + bash <(curl -s https://raw.githubusercontent.com/lfit/releng-global-jjb/master/shell/update-java-alternatives.sh) + source /tmp/java.env +fi + # Disable SC2086 because we want to allow word splitting for $MAVEN_* parameters. # shellcheck disable=SC2086 "$MVN" $SONAR_MAVEN_GOAL \ -- 2.16.6