Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

scoverage plugin not working for project iwht mix of java and scala code #102

Open
paramr opened this issue May 30, 2019 · 7 comments
Open

Comments

@paramr
Copy link

paramr commented May 30, 2019

When scala code references java code and scoverage is used with gradle, I get compilation errors in scala where the java classes are referenced.

this is because in ScoveragePlugin.groovy, we dont copy over java files from the sourceset when creating instrumentedSourceSet (Might be better to copy whole sourceset if possible:

        def instrumentedSourceSet = project.sourceSets.create('scoverage') {

            resources.source(originalSourceSet.resources)
            scala.source(originalSourceSet.scala)

            compileClasspath += originalSourceSet.compileClasspath + project.configurations.scoverage
            runtimeClasspath = it.output + project.configurations.scoverage + originalSourceSet.runtimeClasspath
        }

workaround for now is to add following to build.gradle:

allprojects {
    afterEvaluate { project ->
        def originalSourceSet = project.sourceSets.getByName(
            SourceSet.MAIN_SOURCE_SET_NAME)
        def scoverageSourceSet = project.sourceSets.getByName('scoverage')
        scoverageSourceSet.java.source(originalSourceSet.java)
    }
}
maiflai added a commit that referenced this issue Jun 1, 2019
Issue #102: Honor java sources when running compileScoverageScala
@olisikh
Copy link
Contributor

olisikh commented Jun 1, 2019

Thank you @maiflai for merging the PR.
@paramr this should be fixed in 3.1.3, could you check it out and close this issue if all ok?

@paramr
Copy link
Author

paramr commented Jun 6, 2019

Thanks for fixing this, one small caveate is that default dependencies in gradle goes like scala -> java -> kotlin (if code exists). So we might need to consider kotlin at some point too.

Testing this. Will update soon.

@paramr
Copy link
Author

paramr commented Jun 6, 2019

test is working fine. However we do also have integration tests which is defined as:


task scalaIntegrationTest(dependsOn: ['integrationTestClasses'], type: Test) {
    testClassesDirs = sourceSets.integrationTest.output.classesDirs
    classpath = sourceSets.integrationTest.runtimeClasspath
    mustRunAfter test
    reports {
        junitXml.enabled = true
        html.enabled = true
    }
}

and this fails with:

* What went wrong:
Execution failed for task ':reportScalaIntegrationTestScoverage'.
> No signature of method: static scala.collection.JavaConverters.asScalaBuffer() is applicable for argument types: (ArrayList) values: [[<redacted>/build/scoverage/scoverage.measurements.56, ...]]

@bufistov
Copy link

bufistov commented Jun 12, 2019

I had a similar issue that get solved after removing scala-style plugin dependency from the project. This plugin only works with Scala 2.11 and it seems that latest Scoverage plugin only works with Scala 2.12

@maiflai
Copy link
Contributor

maiflai commented Jun 14, 2019

I'm looking at the 2.11 issue under #94

Sorry,
Stu

@AceHack
Copy link

AceHack commented Jun 19, 2019

I'm having a very similar if not the same issue.

scoverage/scalac-scoverage-plugin#264

olisikh pushed a commit to olisikh/gradle-scoverage that referenced this issue Jun 19, 2019
olisikh pushed a commit to olisikh/gradle-scoverage that referenced this issue Jun 19, 2019
@eyalroth
Copy link
Contributor

eyalroth commented Aug 8, 2019

This shouldn't be a problem for a mixed java/scala project, as these projects should be configured in such a way where the java source set is empty and the scala source set contains both Java and Scala code; otherwise, the Java code cannot access Scala code.

Take a look at my mixed Java / Scala multi-module gradle example project (I'm planning to write a guide for it, as it is not all that self-explanatory), and especially note how the source sets are configured in the gradle/scala.gradle file:

apply plugin: 'scala'

// A way to make Java code able to import Scala code (doesn't work by default)
ext.configureSources = { set, name ->
    set.scala.srcDir("src/$name/java")
    set.java.srcDirs = []
}
configureSources(sourceSets.main, 'main')
configureSources(sourceSets.test, 'test')

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants