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

'No source root found' error for module #191

Closed
gtaylor1981 opened this issue Jan 9, 2024 · 3 comments · Fixed by #196
Closed

'No source root found' error for module #191

gtaylor1981 opened this issue Jan 9, 2024 · 3 comments · Fixed by #196

Comments

@gtaylor1981
Copy link

gtaylor1981 commented Jan 9, 2024

I just tried upgrading from v1.4.11 to the newest v2.0.1 and have encountered a problem.
I recreated this in a minimal project (called my-project) containing a subfolder with a single Scala module (my-module).
When I run mvn clean install it fails with the error:

No source root found for 'C:\GIT\my-project\my-module\my-module\src\main\scala\org\example\MyClass.scala'
(source roots: 'C:\GIT\my-project\my-module\src\main\scala\', 'C:\GIT\my-project\my-module\target\generated-sources\annotations\')

The module name appears twice in the path (...\my-module\my-module\...) which looks like an error to me.

The root POM is almost empty, and the module POM has the plugin configured as follows:

<plugin>
    <groupId>org.scoverage</groupId>
    <artifactId>scoverage-maven-plugin</artifactId>
    <version>2.0.1</version>
    <configuration>
        <additionalForkedProjectProperties>skipTests=false</additionalForkedProjectProperties>
        <highlighting>true</highlighting>
    </configuration>
    <executions>
        <execution>
            <id>scoverage-report</id>
            <goals>
                <goal>report</goal>
            </goals>
            <phase>package</phase>
        </execution>
    </executions>
</plugin>

I attached the project and module POM files if it helps:
project-pom.txt
module-pom.txt

I do see a scoverage-data folder created in C:\GIT\my-project\my-module\target\ as expected.
This contains the source.roots file which looks like:

C:\GIT\my-project\my-module\src\main\java
C:\GIT\my-project\my-module\src\main\scala
C:\GIT\my-project\my-module\target\generated-sources\annotations

Also in this folder is the scoverage.coverage file which contains the source path:

my-module\\src\\main\\scala\\org\\example\\MyClass.scala

This looks ok, but perhaps it is being appended to the module path (C:\GIT\my-project\my-module) which then causes the duplicated module name in the middle?

Do I need to change something in my setup, or is this a bug in the plugin?
Please let me know if I can provide any further info. And many thanks for resurrecting the plugin and releasing the new version.

@jozic
Copy link
Collaborator

jozic commented Jan 10, 2024

Hey @gtaylor1981 i will check it out soon.
Meanwhile, could you please compare your project with integration tests projects located in https://github.com/scoverage/scoverage-maven-plugin/tree/main/src/it ?
they are executed on every PR to this repo and so far I haven't seen the issue

@jozic
Copy link
Collaborator

jozic commented Jan 10, 2024

@gtaylor1981
from a quick check, seems like if the scoverage plugin is defined in parent's pom it works okay, but if it's defined in module's pom, then things go wrong
I will try to investigate why it happens a bit later, but could you please test it from your side and push plugin declaration and configuration to the parent?

@gtaylor1981
Copy link
Author

@jozic Hi, thanks for looking into this.
I tried your suggestion of moving the config to the root, but found it made no difference.

To double check this, I also cloned the repo to be able to run the integration tests and I noticed there are no tests covering my situation, i.e. sub-modules in Scala 3.
I found the most similar one to my situation is test_aggregate so in its main POM, I changed its properties to use Scala 3 (in the same way the other Scala 3 tests do, with these three properties):

<scala.compat.version>3</scala.compat.version>
<scala.version>3.3.1</scala.version>
<scala.library.artifact.id>scala3-library_3</scala.library.artifact.id>

(I also had to update the module01 unit test to Scala 3 by changing def test1() { to def test1(): Unit = {).

Running this integration test reproduced my error message: No source root found for 'C:\GIT\scoverage-maven-plugin\target\it\test_aggregate\module01\module01\src\main\scala\pkg01\HelloService1.scala'

Comparing the scoverage.coverage files from this integration test using Scala 2 and Scala 3 there is a difference in the source path:
Scala 2 has src\main\scala\pkg01\HelloService1.scala
Scala 3 has module01\\src\\main\\scala\\pkg01\\HelloService1.scala


Looking at the source in SCoverageReportMojo.java

Coverage coverage = Serializer.deserialize( coverageFile, project.getBasedir() );

For project module01, project.getBasedir() returns C:\GIT\scoverage-maven-plugin\target\it\test_aggregate\module01

This gets appended to the source path in the coverage file, producing the duplicated module name in the path.

This is as far as I got; I am not sure whether the 'bug' is that module01 is present in the scoverage.coverage file when it should not be, or if the project.getBasedir() should be something like getExecutionRoot(project).getBasedir().

I hope this helps you track down the issue some more.

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