0

I have a jdk 8 full build project in jenkins that works flawlessly. This project has a dependency on lib/tools.jar:

org.jboss.as:jboss-as-clustering-api:jar:7.5.0.Final-redhat-21:provided
com.sun:tools:jar:1.6:system

This system dependency is no problem for jdk 8 because the jdk has tools.jar in the lib folder. My pom.xml mentions the jboss-as-clustering-api.jar. It does not mention tools.jar. The project fetches the source code and builds the project. It runs unit tests. It does not run sonarqube.

Next to my jdk 8 build I created a special jdk 11 sonarqube project. This project runs jdk 11 because sonarqube 9.9 only works with a jdk 11 or higher. The project uses the full build workspace and it only runs sonarqube. It doesn't fetch sourcecode, doesn't build, doesn't run unit tests. It only uses maven 3.2.5 to call sonarqube:

-X -P full-build org.sonarsource.scanner.maven:sonar-maven-plugin:3.4.0.905:sonar -e --settings ${build.maven.settings} -Dsonar.projectVersion=${TARGET_SHORT_VERSION}-${BUILD_NUMBER}

The project fails:

org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal on project tmm: Could not resolve dependencies for project be.bpost.tmm:tmm:pom:27.30.0-SNAPSHOT: Could not find artifact com.sun:tools:jar:1.6 at specified path /usr/local/post/jdk-11.0.2/../lib/tools.jar

How come?

I tried changing JAVA_HOME just before the sonarqube call so that it would point to jdk 8 for lib/tools:

...
JAVA_HOME=/usr/local/post/jdk1.8.0_72

[EnvInject] - Variables injected successfully.
[TMM-MAIN-27.30-FB] $ /usr/local/post/groovy-1.7.10/bin/groovy /usr/local/post/bdf-pr/jenkins-pr2/jenkins-home/platformScripts/scripts/groovy/Sonar/prepare-qb.groovy
Artifactory integration is disabled
[TMM-MAIN-27.30-FB] $ /usr/local/post/jdk-11.0.2/bin/java -classpath /usr/local/post/apache-maven-3.2.5/boot/plexus-classworlds-2.5.2.jar -Dmaven.home=/usr/local/post/apache-maven-3.2.5 -Dclassworlds.conf=/usr/local/post/apache-maven-3.2.5/bin/m2.conf -Xms256m -Xmx1024m -XX:MaxMetaspaceSize=256m -Dsonar.ci.url=${JOB_URL} -Dsonar.scm.url=scm:svn:http://svn.netpost:10080/svn/${ACRONYM}/${SVN_MODULE}/branches/${BRANCH_NAME} -Djava.io.tmpdir=${TEMP_DIR} -Dmaven.wagon.http.ssl.insecure=true -Dmaven.wagon.http.ssl.allowall=true -Dmaven.wagon.http.ssl.ignore.validity.dates=true -Dhttp.proxyHost=${HTTP_PROXY_HOST} -Dhttp.proxyPort=${HTTP_PROXY_PORT} -Dhttp.proxyUser=******** -Dhttp.proxyPassword=******** -Dhttps.proxyHost=${HTTP_PROXY_HOST} -Dhttps.proxyPort=${HTTP_PROXY_PORT} -Dhttps.proxyUser=******** -Dhttps.proxyPassword=******** -Dsonar.scm.url=scm:svn:${SVN_URL} -Dsonar.svn.username=******** -Dsonar.svn.password.secured=**** org.codehaus.plexus.classworlds.launcher.Launcher -f ${ACRONYM}/pom.xml -X -P full-build org.sonarsource.scanner.maven:sonar-maven-plugin:3.4.0.905:sonar -e --settings ${build.maven.settings} -Dsonar.projectVersion=${TARGET_SHORT_VERSION}-${BUILD_NUMBER}

This doesn't work. It still can't find lib/tools.jar. What do I have to do to make sonarqube find this dependency? Googling gives me many results, but they all talk about using maven profiles to seperate the build and the sonarqube run. I already seperated the build and sonarqube. Do I have to use an exclude on tools.jar in my pom file together with a maven profile so that the pom excludes tools.jar when it's on jdk 11 and includes it in jdk 8? How do I do this? Can someone enlighten me?

Djordje Nedovic
  • 559
  • 8
  • 20
gargle
  • 33
  • 7
  • First I would strongly recomment to use the most recent version sonar plugin: https://central.sonatype.com/artifact/org.codehaus.mojo/sonar-maven-plugin/3.9.1.2184 also it looks like you are using an old JDk8 version as well as an old version of Maven 3.2.5... – khmarbaise May 15 '23 at 08:51
  • 1
    Simple answer: it can’t find a `tools.jar` because there is no `tools.jar`. It’s not needed in JDK 11, as the classes formerly contained in `tools.jar` are now in the same place as all other JDK classes—at least those still supported. – Holger May 15 '23 at 13:41
  • So ok, my question, how do I tell my sonarqube project not to look for tools.jar? If I modify the pom files to exclude it my jdk 8 will fail. Does anyone have an example? – gargle May 15 '23 at 15:04
  • Found it! If tools.jar is missing, then exclude it from the artifact that depends on it in the pom.xml. – gargle May 16 '23 at 09:08

1 Answers1

0

Found it!

I added this to the pom.xml.

jdk 8 keeps on working, because it has ${java.home}/../lib/tools.jar. The build uses jboss-as-ejb3 which depends on tools.jar, so we exclude ${java.home}/../lib/tools.jar if it cannot be found:

    <profile>
      <id>default-tools.jar</id>
      <activation>
        <file>
          <missing>${java.home}/../lib/tools.jar</missing>
        </file>
      </activation>
      <dependencies>
        <dependency>
          <groupId>org.jboss.as</groupId>
          <artifactId>jboss-as-ejb3</artifactId>
          <version>7.5.0.Final-redhat-21</version>
          <scope>provided</scope>
          <exclusions>
            <exclusion>
              <groupId>com.sun</groupId>
              <artifactId>tools</artifactId>
            </exclusion>
          </exclusions>
        </dependency>
      </dependencies>
    </profile>
gargle
  • 33
  • 7