Re: JPMS – Test sources extra Java SE module dependencies

2022-07-02 Thread Stanimir Stamenkov

Thank you for the wonderful reference and summary, Daniel!

While I'm parsing the information along with all its references, indeed 
it seems a well-known path.  I'm glad people have taken it to that great 
extent, and have provided guidelines and solutions to newcomers like me.


– Stanimir


Sat, 02 Jul 2022 21:00:41 -0700, /Daniel Widdis/:


You are traveling a well-known path to many of us.

I highly recommend taking a look at junit-platform-maven-plugin:
https://github.com/sormuras/junit-platform-maven-plugin

Blog post outlining how to do what you'e doing is here:
https://sormuras.github.io/blog/2018-09-11-testing-in-the-modular-world.html

TLDR:
1. you keep the one module-info.java in your main project
2. you add a module-info.test in your test directory with 
appropriate command line entries for add-opens (to see your source 
code) and add-reads (essentially replacing the additional 
"requires")



On 7/2/22, 4:46 PM, "Stanimir Stamenkov"  wrote:

 I can't figure out what's the best practice or just proper way for
 setting up a JPMS Maven project with test sources that have additional
 Java SE module dependencies to those of the main sources.
[...]


--

-
To unsubscribe, e-mail: users-unsubscr...@maven.apache.org
For additional commands, e-mail: users-h...@maven.apache.org



Re: JPMS – Test sources extra Java SE module dependencies

2022-07-02 Thread Daniel Widdis
You are traveling a well-known path to many of us.

I highly recommend taking a look at junit-platform-maven-plugin: 
https://github.com/sormuras/junit-platform-maven-plugin

Blog post outlining how to do what you'e doing is here:
https://sormuras.github.io/blog/2018-09-11-testing-in-the-modular-world.html

TLDR:  
1. you keep the one module-info.java in your main project
2. you add a module-info.test in your test directory with appropriate command 
line entries for add-opens (to see your source code) and add-reads (essentially 
replacing the additional "requires")


On 7/2/22, 4:46 PM, "Stanimir Stamenkov"  wrote:

I can't figure out what's the best practice or just proper way for 
setting up a JPMS Maven project with test sources that have additional 
Java SE module dependencies to those of the main sources.

I have the following basic project structure:

 pom.xml
 src/
 ├─ main/
 │  └─ java/
 │ ├─ module-info.java
 │ └─ net/example/stanio/jpms/
 │└─ HelloJPMS.java
 └─ test/
└─ java/
   └─ net/example/stanio/jpms/
  └─ HelloJPMSTest.java

The `module-info.java` is:

 module net.example.stanio.jpms {
 exports net.example.stanio.jpms;
 }

That is the main sources don't have any dependencies other than 
`java.base`, but the tests use some JAXP (`java.xml`).

My `pom.xml` is like:

 
 4.0.0

 net.example.stanio
 maven-jpms
 0.0.1-SNAPSHOT

 maven-jpms

 
 
UTF-8
 9
 
true
 

 
 
 junit
 junit
 4.13.2
 test
 
 

 
 
 
maven-compiler-plugin
3.10.1
 
 
 
 

Running `mvn -V clean test` I'm getting:

```
Apache Maven 3.8.6 (84538c9988a25aec085021c365c560670ad80f63)
Maven home: C:\...
Java version: 11.0.12, vendor: Oracle Corporation, runtime: C:\...
Default locale: en_US, platform encoding: Cp1251
OS name: "windows 10", version: "10.0", arch: "amd64", family: "windows"
[INFO] Scanning for projects...
...
[INFO] --- maven-compiler-plugin:3.10.1:testCompile (default-testCompile) @ 
maven-jpms ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 1 source file to C:\...\maven-jpms\target\test-classes
[INFO] -
[ERROR] COMPILATION ERROR :
[INFO] -
[ERROR] 
/C:/.../maven-jpms/src/test/java/net/example/stanio/jpms/HelloJPMSTest.java:[7,17]
 package javax.xml.transform is not visible
   (package javax.xml.transform is declared in module jdk.pack, but module 
net.example.stanio.jpms does not read it)
[ERROR] 
/C:/.../maven-jpms/src/test/java/net/example/stanio/jpms/HelloJPMSTest.java:[8,27]
 package javax.xml.transform.sax is not visible
   (package javax.xml.transform.sax is declared in module jdk.pack, but 
module net.example.stanio.jpms does not read it)
[ERROR] 
/C:/.../maven-jpms/src/test/java/net/example/stanio/jpms/HelloJPMSTest.java:[9,27]
 package javax.xml.transform.sax is not visible
   (package javax.xml.transform.sax is declared in module jdk.pack, but 
module net.example.stanio.jpms does not read it)
[ERROR] 
/C:/.../maven-jpms/src/test/java/net/example/stanio/jpms/HelloJPMSTest.java:[10,27]
 package javax.xml.transform.stream is not visible
   (package javax.xml.transform.stream is declared in module jdk.pack, but 
module net.example.stanio.jpms does not read it)
[INFO] 4 errors
[INFO] -
[INFO] 

[INFO] BUILD FAILURE
[INFO] 

[INFO] Total time:  2.668 s
[INFO] Finished at: 2022-07-03T01:49:22+03:00
[INFO] 

[ERROR] Failed to execute goal 
org.apache.maven.plugins:maven-compiler-plugin:3.10.1:testCompile 
(default-testCompile) on project maven-jpms: Compilation failure: Compilation 
failure:
...
```

So I've added `src/test/java/module-info.java` like:

 module net.example.stanio.jpms {
 requires java.xml;
 requires junit;
 }

that appears to have solved the test compilation failure.  Note, I had 
to re-declare the other test dependencies (junit), as well. I would 
really like to avoid that double dependency 

JPMS – Test sources extra Java SE module dependencies

2022-07-02 Thread Stanimir Stamenkov
I can't figure out what's the best practice or just proper way for 
setting up a JPMS Maven project with test sources that have additional 
Java SE module dependencies to those of the main sources.


I have the following basic project structure:

pom.xml
src/
├─ main/
│  └─ java/
│ ├─ module-info.java
│ └─ net/example/stanio/jpms/
│└─ HelloJPMS.java
└─ test/
   └─ java/
  └─ net/example/stanio/jpms/
 └─ HelloJPMSTest.java

The `module-info.java` is:

module net.example.stanio.jpms {
exports net.example.stanio.jpms;
}

That is the main sources don't have any dependencies other than 
`java.base`, but the tests use some JAXP (`java.xml`).


My `pom.xml` is like:


4.0.0

net.example.stanio
maven-jpms
0.0.1-SNAPSHOT

maven-jpms


UTF-8
9

true




junit
junit
4.13.2
test






   maven-compiler-plugin
   3.10.1





Running `mvn -V clean test` I'm getting:

```
Apache Maven 3.8.6 (84538c9988a25aec085021c365c560670ad80f63)
Maven home: C:\...
Java version: 11.0.12, vendor: Oracle Corporation, runtime: C:\...
Default locale: en_US, platform encoding: Cp1251
OS name: "windows 10", version: "10.0", arch: "amd64", family: "windows"
[INFO] Scanning for projects...
...
[INFO] --- maven-compiler-plugin:3.10.1:testCompile (default-testCompile) @ 
maven-jpms ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 1 source file to C:\...\maven-jpms\target\test-classes
[INFO] -
[ERROR] COMPILATION ERROR :
[INFO] -
[ERROR] 
/C:/.../maven-jpms/src/test/java/net/example/stanio/jpms/HelloJPMSTest.java:[7,17]
 package javax.xml.transform is not visible
  (package javax.xml.transform is declared in module jdk.pack, but module 
net.example.stanio.jpms does not read it)
[ERROR] 
/C:/.../maven-jpms/src/test/java/net/example/stanio/jpms/HelloJPMSTest.java:[8,27]
 package javax.xml.transform.sax is not visible
  (package javax.xml.transform.sax is declared in module jdk.pack, but module 
net.example.stanio.jpms does not read it)
[ERROR] 
/C:/.../maven-jpms/src/test/java/net/example/stanio/jpms/HelloJPMSTest.java:[9,27]
 package javax.xml.transform.sax is not visible
  (package javax.xml.transform.sax is declared in module jdk.pack, but module 
net.example.stanio.jpms does not read it)
[ERROR] 
/C:/.../maven-jpms/src/test/java/net/example/stanio/jpms/HelloJPMSTest.java:[10,27]
 package javax.xml.transform.stream is not visible
  (package javax.xml.transform.stream is declared in module jdk.pack, but 
module net.example.stanio.jpms does not read it)
[INFO] 4 errors
[INFO] -
[INFO] 
[INFO] BUILD FAILURE
[INFO] 
[INFO] Total time:  2.668 s
[INFO] Finished at: 2022-07-03T01:49:22+03:00
[INFO] 
[ERROR] Failed to execute goal 
org.apache.maven.plugins:maven-compiler-plugin:3.10.1:testCompile 
(default-testCompile) on project maven-jpms: Compilation failure: Compilation 
failure:
...
```

So I've added `src/test/java/module-info.java` like:

module net.example.stanio.jpms {
requires java.xml;
requires junit;
}

that appears to have solved the test compilation failure.  Note, I had 
to re-declare the other test dependencies (junit), as well. I would 
really like to avoid that double dependency bookkeeping, and then having 
duplicated `module-info.java` completely breaks importing the project 
into Eclipse (m2e).


Is there an established approach to this (or similar) setup? Maybe I 
need to fiddle with the `default-testCompile` `` – haven't 
tried yet, but I've just seen this javac option:


  --add-modules (,)*
Root modules to resolve in addition to the initial modules, or all 
modules
on the module path if  is ALL-MODULE-PATH.

--
Stanimir



-
To unsubscribe, e-mail: users-unsubscr...@maven.apache.org
For additional commands, e-mail: users-h...@maven.apache.org