Fixing 'Class is not accessible through the ClassLoader.' warning with Jenkins, SonarQube, and Gradle

前端 未结 2 1860
眼角桃花
眼角桃花 2021-01-01 03:28

When SonarQube analyzes my Java project which is built using Gradle and Jenkins, I get a lot of warnings about third party libraries not being accessible through the ClassLo

相关标签:
2条回答
  • 2021-01-01 03:40

    The following fixed this issue for me in build.gradle

    sonarqube {
        properties {
            def compileDependencies = project.configurations.compile.files.collect {it.path}join(",")
            def compileOnlyDependencies = project.configurations.compileOnly.files.collect {it.path}join(",")
    
            property "sonar.java.libraries", "$compileDependencies,$compileOnlyDependencies"
            property "sonar.test.libraries", "$compileDependencies,$compileOnlyDependencies"
    
        }
    }
    
    0 讨论(0)
  • 2021-01-01 03:42

    You'll have to set sonar.libraries. But in order to set this property manually, you'll have to define a Gradle task that copies all external dependencies to a lib directory, and then use sonar.libraries=path/to/lib/*.jar to reference them. Instead, I'd invoke Sonar via the sonar-runner Gradle plugin, which will take care of setting the above properties (plus sonar.libraries and others) for you.

    0 讨论(0)
提交回复
热议问题