SonarQube Gradle build fails - "Invalid value for sonar.java.test.libraries"

1,473 views
Skip to first unread message

huxleyoo...@gmail.com

unread,
Jan 19, 2017, 2:14:42 AM1/19/17
to SonarQube
I have an Android library project to which I apply a custom Gradle plugin. The custom plugin is responsible for setting up the Android plugin, support library and other dependencies, as well as the Jacoco test coverage and SonarQube plugins.

I managed to get SonarQube working without a problem in the past, but I'm now running into an issue that I can't figure out.  When I run the SonarQube plugin, it will fail with "Invalid value for sonar.java.test.libraries", because it for some reason has populated that property with a folder:
{project.buildDir}/intermediates/dependency-cache/{variantName}

where variantName in this case is 'debug'.  That folder doesn't exist, doesn't get created in the build process, and I'm not sure if it was there previously (while it was still working).  If I create an empty folder matching that path, then the task continues and succeeds.

I went through the SonarQube plugin code on GitHub to figure out where it got that folder, and I can't seem to find it.  I effectively copied the code in the AndroidUtils class in order to emulate what SonarQube was doing, but I don't get the same output.  I.e. when I print out:
project.tasks['sonarqube'].properties['sonar.java.test.libraries']

I get a different result from manually setting up as it is done in the SonarQube plugin, using:

def javaCompiler = project.extensions.getByType(LibraryExtension.class).getLibraryVariants().find { it.name == 'debug' }.javaCompiler
def bootclassPath = project.extensions.getByType(LibraryExtension.class).getBootClasspath()
Set<File> libraries = new LinkedHashSet<>();
libraries.add(bootclassPath)
libraries.addAll(javaCompiler.classpath.files)

where all of this is done in an "afterEvaluate" closure in my build script.

I haven't been able to pinpoint any changes that were made that could cause this to break.

These are the versions of the tools I'm using
Android Studio 2.3 Beta 2
Gradle 3.3
SonarQube Gradle Plugin 2.2.1
Android Gradle Plugin 2.2.3
Android Build Tools 25.0.1 (also fails on 23.0.3)
Message has been deleted

Huxley Oosthuizen

unread,
Jan 19, 2017, 11:28:30 PM1/19/17
to SonarQube
I made a mistake in the above snippet where I was getting javaCompiler from the base variant, instead of the unit test variant. When I fetch the classpath from there, I found the "dependency-cache" folder. Still don't know why this is suddenly a problem, but using the following code in my plugin and manually setting sonar.java.test.libraries I can work around it:

Collection<File> getTestLibraries() {
       
def libraryExtension = project.extensions.getByType(LibraryExtension.class)
       
def libraryVariant = libraryExtension.getLibraryVariants().find {
            it
.name == 'debug'

       
}

       
Set<File> libraries = new LinkedHashSet<>()

        libraries
.addAll(libraryExtension.getBootClasspath())
        libraries
.addAll(libraryVariant.getUnitTestVariant().javaCompiler.classpath.files)
        libraries
.addAll(libraryVariant.getTestVariant().javaCompiler.classpath.files)
        libraries
.findAll { it.exists() }
   
}

Reply all
Reply to author
Forward
0 new messages