maven-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "foo bar (JIRA)" <j...@apache.org>
Subject [jira] [Comment Edited] (MCOMPILER-348) Can't make test-scoped dependencies work with Java 9 modules
Date Thu, 19 Jul 2018 20:17:00 GMT

    [ https://issues.apache.org/jira/browse/MCOMPILER-348?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16549751#comment-16549751
] 

foo bar edited comment on MCOMPILER-348 at 7/19/18 8:16 PM:
------------------------------------------------------------

Ho ho, if you're right this is going to be an interesting issue to investigate for me. I'm
very much a Java lover so if the problem comes from that I'm going to feel a need to signal
this to the higher powers or understand what I can't do.How confident are you that this is
a javac bug? Maybe the confusion comes from "unnamed module" vs "automatic modules", but I
need to read up on that.

Also the reason I want to be able to use these test-scoped dependencies so much is that that
is required for my usual pattern for implementing a modular "DDD application" or "DDD mini-framework"
as an application programmer.

Good idea contacting the Jigsaw mailing list. I do read Java mailing lists from time to time,
including the Jigsaw one. But I'm going to investigate and make a dichotomy/minimization branch
on my side before doing that.I will probably ask you for some more pointers after I do a bit
of investigation if that's ok for you.

 

*edit*:

I do use surefire/failsafe 2.22.0 (and Java 10.0.2, so the latest).

 

For me it doesn't change anything whether I say source/target or release. Same for running
with Java 9 or 10 (that's only a point for "release 9" of course).

 On the other hand, if i say "'release 9" I get:
{code:java}
[WARNING] /G:/projets/wires/wires/wires/wires-core/src/test/java/fr/cla/wires/core/MavenVsJavaModulesReproduceTest.java:[9,54]
class fr.cla.wires.support.oo.ddd.AbstractValueObjectTest in module  is not exported

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.7.0:testCompile
(default-testCompile) on project wires-core: Compilation failure
[ERROR] /G:/projets/wires/wires/wires/wires-core/src/test/java/fr/cla/wires/core/MavenVsJavaModulesReproduceTest.java:
warnings found and -Werror specified
{code}
Whereas if i say "'release 10" I get:
{code:java}
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.7.0:testCompile
(default-testCompile) on project wires-support: Execution default-testCompile of goal org.apache.maven.plugins:maven-compiler-plugin:3.7.0:testCompile
failed.: IllegalArgumentException
{code}
 


was (Author: vandekeizer):
Ho ho, if you're right this is going to be an interesting issue to investigate for me. I'm
very much a Java lover so if the problem comes from that I'm going to feel a need to signal
this to the higher powers or understand what I can't do.How confident are you that this is
a javac bug? Maybe the confusion comes from "unnamed module" vs "automatic modules", but I
need to read up on that.

Also the reason I want to be able to use these test-scoped dependencies so much is that that
is required for my usual pattern for implementing a modular "DDD application" or "DDD mini-framework"
as an application programmer.

Good idea contacting the Jigsaw mailing list. I do read Java mailing lists from time to time,
including the Jigsaw one. But I'm going to investigate and make a dichotomy/minimization branch
on my side before doing that.I will probably ask you for some more pointers after I do a bit
of investigation if that's ok for you.

 

*edit*:

I do use surefire/failsafe 2.22.0 (and Java 10.0.2, so the latest).

 

For me it doesn't change anything whether I say source/target or release. Same for running
with java 9 or 10 (for "release 9").

 On the other hand, if i say "'release 9" I get:
{code:java}
[WARNING] /G:/projets/wires/wires/wires/wires-core/src/test/java/fr/cla/wires/core/MavenVsJavaModulesReproduceTest.java:[9,54]
class fr.cla.wires.support.oo.ddd.AbstractValueObjectTest in module  is not exported

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.7.0:testCompile
(default-testCompile) on project wires-core: Compilation failure
[ERROR] /G:/projets/wires/wires/wires/wires-core/src/test/java/fr/cla/wires/core/MavenVsJavaModulesReproduceTest.java:
warnings found and -Werror specified
{code}
Whereas if i say "'release 10" I get:
{code:java}
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.7.0:testCompile
(default-testCompile) on project wires-support: Execution default-testCompile of goal org.apache.maven.plugins:maven-compiler-plugin:3.7.0:testCompile
failed.: IllegalArgumentException
{code}
 

> Can't make test-scoped dependencies work with Java 9 modules
> ------------------------------------------------------------
>
>                 Key: MCOMPILER-348
>                 URL: https://issues.apache.org/jira/browse/MCOMPILER-348
>             Project: Maven Compiler Plugin
>          Issue Type: Bug
>    Affects Versions: 3.7.0
>         Environment: $ mvn -version
> Apache Maven 3.5.4 (1edded0938998edf8bf061f1ceb3cfdeccf443fe; 2018-06-17T20:33:14+02:00)
> Maven home: G:\software\apache-maven-3.5.4-bin\apache-maven-3.5.4
> Java version: 9.0.4, vendor: Oracle Corporation, runtime: C:\Program Files\Java\jdk-9.0.4
> Default locale: fr_FR, platform encoding: Cp1252
> OS name: "windows 7", version: "6.1", arch: "amd64", family: "windows"
>            Reporter: foo bar
>            Priority: Major
>              Labels: Java9, jigsaw, scope, test
>         Attachments: MCOMPILER-348-reproduce.7z, mvn-X-clean-install-output.txt
>
>
> h1. In short
> With Java 9 if I declare both the test-scoped dependency and the Java 9 modules the test
doesn't compile anymore (mvn clean install output):
> {code:java}
> [ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.7.0:testCompile
(default-testCompile) on project clientmod: Compilation failure: Compilation failure:
> [ERROR] /G:/projets/wires/wires/wires/clientmod/src/test/java/qux/DerivedTest.java:[3,11]
package api does not exist
> [ERROR] /G:/projets/wires/wires/wires/clientmod/src/test/java/qux/DerivedTest.java:[11,13]
cannot find symbol
> [ERROR]   symbol:   class Base
> [ERROR]   location: class qux.DerivedTest
> [ERROR] -> [Help 1]
> {code}
> *That same test {{DerivedTest}} compiles and runs just fine in IntelliJ!* So it's probably
worth it to look at the different flags that Maven passes to javac and java compared to IJ?

> h1. Explanation of the 2 modules, and what fails
> I have a java 9 maven project with 2 modules: {{apimod}} and {{clientmod}}. Module {{clientmod}}
depends on module {{apimod}} (those modules are both Maven modules and Java 9 modules).
> Also, i want module {{clientmod}} to be able to reuse not only production code from {{apimod}},
*but also test code*. This is a common pattern, that I used many times with Java 8. With Java
9 (it's the same with Java 10) it also works fine, as long as i don't declare module-info.java
(that is, as long as I don't run with the module system).
> But as soon as I do, enabling the test dependency seems to disable the production dependency:
{{api.Base}} (an {{src/main}} class of module {{apimod}}) is no longer visible from {{qux.DerivedTest}}
(an {{src/test}} class of module {{clientmod}}). The test doesn't compile anymore. (_Note
that every class is in a different package to eliminate split packages as a cause of the problem_)
> This is with: Java 9.0.4 (it's the same with Java 10), Maven 3.5.3, maven-compiler-plugin
3.7.0
>  
> h1. A project to reproduce the issue
> h2. The code
> I "dichotomized" the issue with a failing test in a branch:
> {code:java}
> git clone https://github.com/vandekeiser/wires.git
> git checkout MCOMPILER_ISSUE2
> mvn clean install{code}
> -> BUILD FAIL (compilation error in the test of {{clientmod}})
> h2. The Maven test-scoped dependency
> I want module {{clientmod}} to be able to reuse not only production code from {{apimod}}
but also test code. With Maven you do it like that ({{clientmod/pom.xml}}):
> {code:java}
> <dependency>
>     <groupId>fr.cla</groupId>
>     <artifactId>apimod</artifactId>
>     <version>${project.version}</version>
>     <classifier>tests</classifier>
>     <scope>test</scope>
> </dependency>
> {code}
> h2. The Java 9 modules
> {code:java}
> module apimod {
>     exports api;
> }
> module clientmod {
>     requires apimod;
> }
> {code}
> h2. The failure when trying to enable both module systems
> With Java 9 if I declare both the test-scoped dependency and the Java 9 modules the test
doesn't compile anymore ({{mvn clean install}} output):
> {code:java}
> [ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.7.0:testCompile
(default-testCompile) on project clientmod: Compilation failure: Compilation failure:
> [ERROR] /G:/projets/wires/wires/wires/clientmod/src/test/java/qux/DerivedTest.java:[3,11]
package api does not exist
> [ERROR] /G:/projets/wires/wires/wires/clientmod/src/test/java/qux/DerivedTest.java:[11,13]
cannot find symbol
> [ERROR]   symbol:   class Base
> [ERROR]   location: class qux.DerivedTest
> [ERROR] -> [Help 1]
> {code}
> h1. My analysis so far
> h2. It works if i remove the test-scope dependency
> If i comment the test-dependency, {{mvn clean install}} passes:
> {code:java}
> //import baz.BaseTest;
> DerivedTest /*extends BaseTest*/
> {code}
> {code:java}
> <!--Comment the following to make mvn clean install pass (but then you can't have
DerivedTest extends BaseTest)-–>
> <!--<dependency>-->
> <!--<groupId>fr.cla</groupId>-->
> <!--<artifactId>apimod</artifactId>-->
> <!--<version>${project.version}</version>-->
> <!--<classifier>tests</classifier>-->
> <!--<scope>test</scope>-->
> <!--</dependency>-->
> {code}
>  
> h2. Trying to pass explicit module flags to the JVM
> After asking here: [https://stackoverflow.com/questions/50122838/cant-make-maven-test-scoped-dependencies-work-with-java-9-nor-10-modules]
> I tried the following flags to move {{apimod-1.0-SNAPSHOT-tests.jar}} from {{--module-path-}}
to {{-patch-module clientmod}}, it compiles but then surefire fails so it must not be right
either (anyway passing all those flags is fragile):
> {code:java}
>  <!--This makes the test compile even with the test-scoped dependency present, but
then surefire fails (so probably those flags are incorrect too)-->
> <compilerArgs>
>     <arg>--module-source-path=./*/src/main/java;./*/src/test/java/;</arg>
>     <arg>
>         --source-path=/G/projets/wires/wires/wires/apimod/src/main/java;/G/projets/wires/wires/wires/apimod/src/test/java;/G/projets/wires/wires/wires/clientmod/src/test/java;/G/projets/wires/wires/wires/clientmod/src/main/java;
>     </arg>
>     <arg>-Xlint:all</arg>
>     <arg>
>         --patch-module=clientmod=/G/projets/wires/wires/wires/clientmod/target/classes;/G/projets/wires/wires/wires/clientmod/src/test/java;/G/projets/wires/wires/wires/apimod/target/apimod-1.0-SNAPSHOT.jar;/G/projets/wires/wires/wires/apimod/target/apimod-1.0-SNAPSHOT-tests.jar;
>     </arg>
>     <arg>--add-reads=apimod=ALL-UNNAMED</arg>
>     <arg>--add-reads=clientmod=ALL-UNNAMED</arg>
>     <arg>--add-exports=apimod/api=ALL-UNNAMED</arg>
>     <arg>--add-exports=clientmod/client=ALL-UNNAMED</arg>
>     <arg>--add-modules=apimod</arg>
> </compilerArgs>
> {code}
> Just mentioning this in case the problem would be wrong javac flags.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Mime
View raw message