testExcludes/Includes to compile test with different java version

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
17 messages Options
Reply | Threaded
Open this post in threaded view
|

testExcludes/Includes to compile test with different java version

frauboes
Hi,


I have a question about testExcludes and testIncludes.

My project (a clone of the kryo repo) has 2 profiles, one for >= java 8
(j8) and one for >= java 14 (j14). A test file T has to be compiled with
java 14 --preview-enabled. j8 compiles all test files except for T, j14
should only compile T. The aim is that when java 14 is available, all
tests except for T are compiled without --preview-enabled and only T is
compiled with --preview-enabled. However, when run with java 14, j14
compiles T *and* re-compiles all other tests.

I assume the testExcludes/testIncludes filters are not set correctly.
Any idea what the problem is?

Thanks!

Julia


path of T: /test/com/esotericsoftware/kryo/serializers/java14ge/T.java

original pom: https://github.com/EsotericSoftware/kryo/blob/master/pom.xml

profiles added to original pom:

     <profiles>
         <profile>
             <id>java8ge</id>
             <activation>
                 <jdk>[1.8,)</jdk>
             </activation>
             <build>
                 <plugins>
                     <plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
                         <inherited>true</inherited>
                         <configuration>
                             <testExcludes>
<testExclude>**/java14ge/**</testExclude>
                             </testExcludes>
                         </configuration>
                     </plugin>
                 </plugins>
             </build>
         </profile>
         <profile>
             <id>java14ge</id>
             <activation>
                 <jdk>[14,)</jdk>
             </activation>
             <build>
                 <plugins>
                     <plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
                         <inherited>true</inherited>
                         <executions>
                             <execution>
<id>jdk14ge-testCompile</id>
<phase>test-compile</phase>
                                 <goals>
<goal>testCompile</goal>
                                 </goals>
                                 <configuration>
<release>${java.vm.specification.version}</release>
                                     <compilerArgs>
<arg>--enable-preview</arg>
                                     </compilerArgs>
                                     <testIncludes>
<testInclude>**/java14ge/**</testInclude>
                                     </testIncludes>
                                     <testExcludes>
<testExclude>com/**</testExclude>
                                     </testExcludes>
                                 </configuration>
                             </execution>
                         </executions>
                     </plugin>
                 </plugins>
             </build>
         </profile>
     </profiles>


$mvn clean test-compile

...

[INFO] --- maven-compiler-plugin:3.8.1:testCompile (default-testCompile)
@ kryo ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 41 source files to <kryo clone>/target/test-classes
...
[INFO]
[INFO] --- maven-compiler-plugin:3.8.1:testCompile (jdk14ge-testCompile)
@ kryo ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 42 source files to <kryo clone>/target/test-classes
...

Reply | Threaded
Open this post in threaded view
|

Re: testExcludes/Includes to compile test with different java version

frauboes
Sorry for formatting, let's try this again

<profile>
      <id>java8ge</id>
      <activation>
          <jdk>[1.8,)</jdk>
      </activation>
      <build>
      <plugins>
          <plugin>
              <groupId>org.apache.maven.plugins</groupId>
              <artifactId>maven-compiler-plugin</artifactId>
              <inherited>true</inherited>
              <configuration>
                  <testExcludes>
                      <testExclude>**/java14ge/**</testExclude>
                  </testExcludes>
              </configuration>
          </plugin>
      </plugins>
      </build>
</profile>

<profile>
      <id>java14ge</id>
      <activation>
          <jdk>[14,)</jdk>
      </activation>
      <build>
      <plugins>
          <plugin>
              <groupId>org.apache.maven.plugins</groupId>
              <artifactId>maven-compiler-plugin</artifactId>
              <inherited>true</inherited>
              <executions>
                  <execution>
                      <id>jdk14ge-testCompile</id>
                      <phase>test-compile</phase>
                      <goals>
                          <goal>testCompile</goal>
                      </goals>
                      <configuration>
                          <release>${java.vm.specification.version}</release>
                          <compilerArgs>
                              <arg>--enable-preview</arg>
                          </compilerArgs>
                          <testIncludes>
                              <testInclude>**/java14ge/**</testInclude>
                          </testIncludes>
                          <testExcludes>
                              <testExclude>com/**</testExclude>
                          </testExcludes>
                      </configuration>
                  </execution>
              </executions>
          </plugin>
      </plugins>
      </build>
</profile>


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: testExcludes/Includes to compile test with different java version

Alexander Kriegisch-2
In reply to this post by frauboes
Hi mailing list owners!

I tried to send an HTML message before. Usually I don't do that except
for cases in which I think that <pre> blocks or inline formatting such
as code or bold font would be more helpful than auto-wrapped, chaotic
source code or all-ASCII text. I was kinds shocked to get this response
in the 21st century:

> Hi. This is the qmail-send program at apache.org. I'm afraid I wasn't
> able to deliver your message to the following addresses. This is a
> permanent error; I've given up. Sorry it didn't work out.
>
> <[hidden email]>: ezmlm-reject: fatal: Sorry, I don't accept
> messages of MIME Content-Type 'text/html' (#5.2.3)

As I said, I also still write 90% text-only mails, but this enforced
kind of purism on a mailing list is rather shocking. Maybe you want to
reconsider your policy?


------------------------------------------------------------------------


Hi Julia.

I am not quite sure why the java14ge profile should only compile and run
a single test and not all tests. The more intuitive way to organise the
build would be to run all relevant tests for all JDKs, i.e. the JDK 14
tests being a superset of the JDK 8 tests. But you asked for a "logical
XOR", i.e. either/or solution, so I am recommending you to use

mvn help:effective-pom

in order to inspect your configuration. If you look at the effective
POM, you will see that you put your JDK8 compiler configuration with
testExcludes into the general plugin configuration section rather than
in the one for goal testCompile. That parameter only exists there,
though.

You can also combine with -P java8ge,!java14ge or -P !java8ge,java14ge
in order to explicitly check for a certain profile version and override
auto activation.

One way to make your respective test compilations mutually exclusive
would be to override the default execution default-testCompile which
would otherwise be included in each profile unless deactivated via
<phase>none</phase>. So how about this?


<profiles>

  <profile>
    <id>java8ge</id>
    <activation>
      <jdk>[1.8,)</jdk>
    </activation>
    <build>
      <plugins>
        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-compiler-plugin</artifactId>
          <version>3.8.1</version>
          <inherited>true</inherited>
          <executions>
            <execution>
              <id>default-testCompile</id>
              <phase>test-compile</phase>
              <goals>
                <goal>testCompile</goal>
              </goals>
              <configuration>
                <testExcludes>
                  <testExclude>**/java14ge/**</testExclude>
                </testExcludes>
              </configuration>
            </execution>
          </executions>
        </plugin>
      </plugins>
    </build>
  </profile>

  <profile>
    <id>java14ge</id>
    <activation>
      <jdk>[14,)</jdk>
    </activation>
    <build>
      <plugins>
        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-compiler-plugin</artifactId>
          <version>3.8.1</version>
          <inherited>true</inherited>
          <executions>
            <execution>
              <id>default-testCompile</id>
              <phase>test-compile</phase>
              <goals>
                <goal>testCompile</goal>
              </goals>
              <configuration>
                <release>${java.vm.specification.version}</release>
                <compilerArgs>
                  <arg>--enable-preview</arg>
                </compilerArgs>
                <testIncludes>
                  <testInclude>**/java14ge/**</testInclude>
                </testIncludes>
                <testExcludes>
                  <testExclude>com/**</testExclude>
                </testExcludes>
              </configuration>
            </execution>
          </executions>
        </plugin>
      </plugins>
    </build>
  </profile>

</profiles>
 

Kind regards
--
Alexander Kriegisch
https://scrum-master.de

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Re: testExcludes/Includes to compile test with different java version

Thorsten Heit-3
Hi,

> I am not quite sure why the java14ge profile should only compile and run
> a single test and not all tests. The more intuitive way to organise the
> build would be to run all relevant tests for all JDKs, i.e. the JDK 14
> tests being a superset of the JDK 8 tests. But you asked for a "logical
> XOR", i.e. either/or solution, so I am recommending you to use
>
> mvn help:effective-pom
>
> in order to inspect your configuration. If you look at the effective
> POM, you will see that you put your JDK8 compiler configuration with
> testExcludes into the general plugin configuration section rather than
> in the one for goal testCompile. That parameter only exists there,
> though.
>
> You can also combine with -P java8ge,!java14ge or -P !java8ge,java14ge
> in order to explicitly check for a certain profile version and override
> auto activation.
>
> One way to make your respective test compilations mutually exclusive
> would be to override the default execution default-testCompile which
> would otherwise be included in each profile unless deactivated via
> <phase>none</phase>. So how about this?


I'd suggest a different solution. It looks more complex, but in the end
lets you clearly differ between "normal" Java-8-compatible code and code
that has to use Java >= 14:

Basically use three profiles:
- The first is used as long as you're using Java 8
  It only instructs m-compiler-p to use JDK 1.8 as source and target for
your code

- The second is active when you use Java >= 9:
  It does the same as the first, but uses the "release" flag of the
compiler

- The third uses a feature of m-compiler-p to create a multirelease output
with only a single project; see
https://github.com/apache/maven-compiler-plugin/blob/master/src/it/multirelease-patterns/singleproject-runtime/pom.xml
:
  Normal code under src/main/java and src/test/java is compiled with the
default settings from profile 1 or 2, and additional code under
src/main/java14 and src/test/java14 is compiled against Java 14.



<properties>
 <maven.compiler.plugin.version>3.8.1</maven.compiler.plugin.version>
</properties>

<profiles>
        <profile>
                <id>jdk8</id>
                <activation>
                        <jdk>[,9)</jdk>
                </activation>
                <build>
                        <pluginManagement>
                                <plugins>
                                        <plugin>
 <groupId>org.apache.maven.plugins</groupId>
 <artifactId>maven-compiler-plugin</artifactId>
 <version>${maven.compiler.plugin.version}</version>
                                                <configuration>
 <source>1.8</source>
 <target>1.8</target>
                                                </configuration>
                                        </plugin>
                                </plugins>
                        </pluginManagement>
                </build>
        </profile>

        <profile>
                <id>jdk9+</id>
                <activation>
                        <jdk>[9,)</jdk>
                </activation>
                <build>
                        <pluginManagement>
                                <plugins>
                                        <plugin>
 <groupId>org.apache.maven.plugins</groupId>
 <artifactId>maven-compiler-plugin</artifactId>
 <version>${maven.compiler.plugin.version}</version>
                                                <configuration>
 <release>8</release>
                                                </configuration>
                                        </plugin>
                                </plugins>
                        </pluginManagement>
                </build>
        </profile>

        <!-- Java >=14 as default: -->

        <profile>
                <id>jdk14</id>
                <activation>
                        <jdk>[14,)</jdk>
                        <file>
 <exists>${basedir}/src/main/java14</exists>
                        </file>
                </activation>
                <build>
                        <pluginManagement>
                                <plugins>
                                        <plugin>
 <groupId>org.apache.maven.plugins</groupId>
 <artifactId>maven-compiler-plugin</artifactId>
 <version>${maven.compiler.plugin.version}</version>
                                                <executions>
                                                        <!-- see
https://github.com/apache/maven-compiler-plugin/blob/master/src/it/multirelease-patterns/singleproject-runtime/pom.xml: 
-->
                                                        <execution>
 <id>jdk14-compile</id>
                                                                <goals>
 <goal>compile</goal>
                                                                </goals>
 <configuration>
 <release>14</release>
 <compileSourceRoots>
 <compileSourceRoot>${project.basedir}/src/main/java14</compileSourceRoot>
 </compileSourceRoots>
 <multiReleaseOutput>true</multiReleaseOutput>
 </configuration>
                                                        </execution>
                                                        <execution>
 <id>jdk14-testcompile</id>
                                                                <goals>
 <goal>testCompile</goal>
                                                                </goals>
 <configuration>
 <release>14</release>
 <testCompileSourceRoots>
 
<testCompileSourceRoot>${project.basedir}/src/test/java14</compileSourceRoot>
 </testCompileSourceRoots>
 <compilerArgs>
 <arg>--enable-preview</arg>
 </compilerArgs>
 </configuration>
                                                        </execution>
                                                </executions>
                                        </plugin>

                                        <!-- mark the Jar as multi-release
jar so that it is placed -->
                                        <!-- by the compiler on the module
path instead of the -->
                                        <!-- classpath: -->

                                        <plugin>
 <groupId>org.apache.maven.plugins</groupId>
 <artifactId>maven-jar-plugin</artifactId>
                                                <executions>
                                                        <execution>
 <id>default-jar</id>
 <configuration>
 <archive>
 <manifestEntries>
        <Multi-Release>true</Multi-Release>
 </manifestEntries>
 </archive>
 </configuration>
                                                        </execution>
                                                </executions>
                                        </plugin>
                                </plugins>
                        </pluginManagement>
                </build>
        </profile>
</profiles>




HTH

Thorsten
Reply | Threaded
Open this post in threaded view
|

Re: testExcludes/Includes to compile test with different java version

frauboes
Hi,

Thanks for your suggestions!

Thorsten, given that no source but only a single test file is handled
differently, I'm not sure the suggestion is what I'm looking for. I
tried to get it to work but the testCompileSourceRoot element was not
recognized.

Alexander,

> I am not quite sure why the java14ge profile should only compile and run
> a single test and not all tests. The more intuitive way to organise the
> build would be to run all relevant tests for all JDKs, i.e. the JDK 14
> tests being a superset of the JDK 8 tests.

AFAIKS, the project is usually compiled and run with JDK 8 or 11. The
test I added is the only file that requires JDK 14 with preview features
enabled for compilation and running. Other sources and test sources
might break when compiled or run with JDK 14, that's the reason behind
the XOR solution, it seems like the simplest approach.

> I am recommending you to use
>
> mvn help:effective-pom

Thanks for the pointer, that's definitely helpful.

> One way to make your respective test compilations mutually exclusive
> would be to override the default execution default-testCompile which
> would otherwise be included in each profile unless deactivated via
> <phase>none</phase>.

I assumed there was a default execution of default-testCompile, thanks
for confirming that.

> So how about this?
>
>
> <profiles>
>
>    <profile>
>      <id>java8ge</id>
>      <activation>
>        <jdk>[1.8,)</jdk>
>      </activation>
>      <build>
>        <plugins>
>          <plugin>
> <groupId>org.apache.maven.plugins</groupId>
> <artifactId>maven-compiler-plugin</artifactId>
>            <version>3.8.1</version>
>            <inherited>true</inherited>
>            <executions>
>              <execution>
>                <id>default-testCompile</id>
>                <phase>test-compile</phase>
>                <goals>
>                  <goal>testCompile</goal>
>                </goals>
>                <configuration>
>                  <testExcludes>
>                    <testExclude>**/java14ge/**</testExclude>
>                  </testExcludes>
>                </configuration>
>              </execution>
>            </executions>
>          </plugin>
>        </plugins>
>      </build>
>    </profile>
>
>    <profile>
>      <id>java14ge</id>
>      <activation>
>        <jdk>[14,)</jdk>
>      </activation>
>      <build>
>        <plugins>
>          <plugin>
> <groupId>org.apache.maven.plugins</groupId>
> <artifactId>maven-compiler-plugin</artifactId>
>            <version>3.8.1</version>
>            <inherited>true</inherited>
>            <executions>
>              <execution>
>                <id>default-testCompile</id>
>                <phase>test-compile</phase>
>                <goals>
>                  <goal>testCompile</goal>
>                </goals>
>                <configuration>
> <release>${java.vm.specification.version}</release>
>                  <compilerArgs>
>                    <arg>--enable-preview</arg>
>                  </compilerArgs>
>                  <testIncludes>
>                    <testInclude>**/java14ge/**</testInclude>
>                  </testIncludes>
>                  <testExcludes>
>                    <testExclude>com/**</testExclude>
>                  </testExcludes>
>                </configuration>
>              </execution>
>            </executions>
>          </plugin>
>        </plugins>
>      </build>
>    </profile>
>
> </profiles>

I added these 2 profiles to the original pom. mvn clean install runs
default-testCompile ok with JDK 14. With JDK 11 and JDK 8 it results in
compilation errors during default-testCompile:

[INFO] ------------------< com.esotericsoftware:kryo-parent
 >------------------
[INFO] Building Kryo Parent
5.0.0-RC10-SNAPSHOT                           [1/4]
[INFO] --------------------------------[ pom
]---------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ kryo-parent ---
[INFO] Deleting /Users/jboes/IdeaProjects/kryo-mirror/target
[INFO]
[INFO] --- maven-enforcer-plugin:1.0:enforce (enforce-maven) @
kryo-parent ---
[INFO]
[INFO] --- maven-compiler-plugin:3.8.1:testCompile (default-testCompile)
@ kryo-parent ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 42 source files to
/Users/jboes/IdeaProjects/kryo-mirror/target/test-classes
[INFO]
/Users/jboes/IdeaProjects/kryo-mirror/test/com/esotericsoftware/kryo/KryoTestCase.java:
Some input files use unchecked or unsafe operations.
[INFO]
/Users/jboes/IdeaProjects/kryo-mirror/test/com/esotericsoftware/kryo/KryoTestCase.java:
Recompile with -Xlint:unchecked for details.

...

[INFO] Reactor Summary for Kryo Parent 5.0.0-RC10-SNAPSHOT:
[INFO]
[INFO] Kryo Parent ........................................ FAILURE [ 
2.328 s]
[INFO] Kryo ............................................... SKIPPED
[INFO] Kryo 5 ............................................. SKIPPED
[INFO] Kryo Benchmarks .................................... SKIPPED
[INFO]
------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO]
------------------------------------------------------------------------
[INFO] Total time:  3.266 s
[INFO] Finished at: 2020-08-25T10:05:47+01:00
[INFO]
------------------------------------------------------------------------
[ERROR] Failed to execute goal
org.apache.maven.plugins:maven-compiler-plugin:3.8.1:testCompile
(default-testCompile) on project kryo-parent: Compilation failure:
Compilation failure:

The effective pom lists default-testCompile as such:


pluginmanagement

          <plugin>
<artifactId>maven-compiler-plugin</artifactId>
           <version>3.8.1</version>
           <executions>
             <execution>
               <id>default-testCompile</id>
               <phase>test-compile</phase>
               <goals>
                 <goal>testCompile</goal>
               </goals>
               <configuration>
                 <testExcludes>
<testExclude>jdk14ge/**</testExclude>
                 </testExcludes>
                 <source>1.8</source>
                 <target>1.8</target>
                 <encoding>utf-8</encoding>
               </configuration>
             </execution>
           </executions>
           <inherited>true</inherited>
           <configuration>
             <source>1.8</source>
             <target>1.8</target>
             <encoding>utf-8</encoding>
           </configuration>
         </plugin>

profiles

       <profile>
         <id>jdk8ge</id>
         <activation>
           <jdk>[1.8,)</jdk>
         </activation>
         <build>
           <plugins>
             <plugin>
<artifactId>maven-compiler-plugin</artifactId>
               <version>3.8.1</version>
               <executions>
                 <execution>
                   <id>default-testCompile</id>
                   <phase>test-compile</phase>
                   <goals>
                     <goal>testCompile</goal>
                   </goals>
                   <configuration>
                     <testExcludes>
<testExclude>jdk14ge/**</testExclude>
                     </testExcludes>
                   </configuration>
                 </execution>
               </executions>
               <inherited>true</inherited>
             </plugin>
           </plugins>
         </build>
       </profile>

       <profile>
         <id>jdk14ge</id>
         <activation>
           <jdk>[14,)</jdk>
         </activation>
         <build>
           <plugins>
             <plugin>
<artifactId>maven-compiler-plugin</artifactId>
               <version>3.8.1</version>
               <executions>
                 <execution>
                   <id>default-testCompile</id>
                   <phase>test-compile</phase>
                   <goals>
                     <goal>testCompile</goal>
                   </goals>
                   <configuration>
                     <release>11</release>
                     <compilerArgs>
                       <arg>--enable-preview</arg>
                     </compilerArgs>
                     <testIncludes>
<testInclude>jdk14ge/**</testInclude>
                     </testIncludes>
                     <testExcludes>
<testExclude>com/**</testExclude>
                     </testExcludes>
                   </configuration>
                 </execution>
               </executions>
               <inherited>true</inherited>
             </plugin>


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: testExcludes/Includes to compile test with different java version

frauboes
In reply to this post by Alexander Kriegisch-2
Brief update: It turns out that mvn clean and install have to be run separately due to a problem with the shade plugin, so

$ mvn clean && mvn install

works with the 2 added profiles and JDK 14. However, I see the same compilation error as mentioned before when running with JDK 11.


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: testExcludes/Includes to compile test with different java version

Alexander Kriegisch-2
Julia Boes schrieb am 25.08.2020 19:39 (GMT +07:00):

> Brief update: It turns out that mvn clean and install have to be run
> separately due to a problem with the shade plugin, so
>
> $ mvn clean && mvn install
>
> works with the 2 added profiles and JDK 14.

This seems to be unrelated to your problem, but anyway, just in case you
are referring to the fact that Maven Shade will try to re-shade an
already shaded JAR, showing lots of warnings for duplicate classes, I
remember I had that too in the past and this helps avoid it:

<plugin>
  <artifactId>maven-jar-plugin</artifactId>
  <configuration>
    <!-- Re-create original JAR in order to avoid re-shading already shaded JAR in non-clean builds -->
    <forceCreation>true</forceCreation>
  </configuration>
</plugin>

Just in case you also create a shaded source JAR like me, you also want to use:

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-source-plugin</artifactId>
  <configuration>
    <!-- Re-create original source JAR in order to avoid re-shading already shaded JAR in non-clean builds -->
    <forceCreation>true</forceCreation>
  </configuration>
</plugin>


> However, I see the same compilation error as mentioned before when
> running with JDK 11.

I will look into it and reply separately.

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: testExcludes/Includes to compile test with different java version

Alexander Kriegisch-2
In reply to this post by frauboes
Julia Boes schrieb am 25.08.2020 16:50 (GMT +07:00):

> I added these 2 profiles to the original pom. mvn clean install runs
> default-testCompile ok with JDK 14. With JDK 11 and JDK 8 it results in
> compilation errors during default-testCompile:
>
> (...)
> [INFO] Building Kryo Parent 5.0.0-RC10-SNAPSHOT
> (...)
> [INFO] --- maven-compiler-plugin:3.8.1:testCompile (default-testCompile) ...
> [INFO] Changes detected - recompiling the module!
> [INFO] Compiling 42 source files to ...
> (...)
>
> [INFO] Kryo Parent ... FAILURE

I am assuming your project is some kind of fork of [1]. The project
structure is quite unusual, having one parent POM and 3 children, all in
the project's root directory and all using the same source tree with
different settings. The parent POM [2] has <packaging>pom</packaging>,
as is to be expected because it defines three submodules. I think the
original author's intention is not to compile anything in the parent
POM, only to configure plugins via <pluginManagement> in order to use
same configuration later in the children in their respective <plugins>
sections. I cannot say for sure, but probably you just copied & pasted
my plugin configurations into the parent POM's <plugin> section instead
of <pluginManagement> -> <plugins>, consequently kicking off test
compilation from the parent. I guess you want to change that.

BTW, if you can fork the original repo for me and just add enough
commits to reproduce your situation, I can take a closer look.
Currently, I have to speculate based on the information I have, which is
less than ideal.


[1] https://github.com/EsotericSoftware/kryo
[2] https://github.com/EsotericSoftware/kryo/blob/master/pom.xml

Regards
--
Alexander Kriegisch
https://scrum-master.de

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: testExcludes/Includes to compile test with different java version

frauboes
In reply to this post by Alexander Kriegisch-2
Hi Alexander,

Interesting - I don't see warnings for duplicate classes so not sure
it's the same problem.

Thanks anyways!

Julia


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: testExcludes/Includes to compile test with different java version

frauboes
In reply to this post by Alexander Kriegisch-2
Hi Alexander,

> I cannot say for sure, but probably you just copied & pasted
> my plugin configurations into the parent POM's <plugin> section instead
> of <pluginManagement> -> <plugins>, consequently kicking off test
> compilation from the parent. I guess you want to change that.

That's exactly what I did. Moving the configuration to pluginManagement
makes sense, but how would you add profiles to it? Or would you need to
add the profile information in the child poms?

> BTW, if you can fork the original repo for me and just add enough
> commits to reproduce your situation, I can take a closer look.
> Currently, I have to speculate based on the information I have, which is
> less than ideal.

I know it's not ideal but I can't share a public fork at the moment.

Thanks for your help on this!

Julia


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: testExcludes/Includes to compile test with different java version

Alexander Kriegisch-2
Julia Boes schrieb am 27.08.2020 15:09 (GMT +07:00):

>> I cannot say for sure, but probably you just copied & pasted my
>> plugin configurations into the parent POM's <plugin> section instead
>> of <pluginManagement> -> <plugins>, consequently kicking off test
>> compilation from the parent. I guess you want to change that.
>
> That's exactly what I did. Moving the configuration to
> pluginManagement makes sense, but how would you add profiles to it? Or
> would you need to add the profile information in the child poms?

Yes, if you add/override plugin configuration which does not apply to
the whole project but just to some modules, you should add it there.
Just give it a try, I cannot test for you without an MCVE.

>> BTW, if you can fork the original repo for me and just add enough
>> commits to reproduce your situation, I can take a closer look.
>> Currently, I have to speculate based on the information I have, which
>> is less than ideal.
>
> I know it's not ideal but I can't share a public fork at the moment.

Read again, please. I suggested to fork the *original* Kryo repo and add
just enough Maven config to reproduce the problem. I did not request a
fork of your internal repo.

See also: https://stackoverflow.com/help/mcve

--
Alexander Kriegisch
https://scrum-master.de

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: testExcludes/Includes to compile test with different java version

frauboes
Hi Alexander,

Sorry for the delay. Here's the MCVE fork

https://github.com/oracle/kryo/tree/records

I followed your suggestion and moved the compiler config to the relevant
children's poms (pom-main, pom-versioned). Compilation works as expected
now.

To recap: RecordSerializerTest (t) requires jdk 14 --enable-preview for
compilation and test run.

$ mvn clean && mvn install

with jdk-14.0.1 compiles t with --enable-preview and all other tests
without the flag

with jdk-11.0.8 compiles all tests but t Similarly, I tried to set
executions for the test goal to achieve the following: (1) with
jdk-14.0.1 runs t with --enable-preview and all other tests without the
flag
(2) with jdk-11.0.8 runs all tests but t

(2) works fine with the current configuration, but (1) runs *no* tests at all. I inspected the effective pom and can see that the profile for <jdk11 from the parent pom is inherited, but I'm not sure if that's the problem.

Again, thanks for your help so far!

Regards,
Julia


On 28/08/2020 04:17, Alexander Kriegisch wrote:

> Julia Boes schrieb am 27.08.2020 15:09 (GMT +07:00):
>
>>> I cannot say for sure, but probably you just copied & pasted my
>>> plugin configurations into the parent POM's <plugin> section instead
>>> of <pluginManagement> -> <plugins>, consequently kicking off test
>>> compilation from the parent. I guess you want to change that.
>> That's exactly what I did. Moving the configuration to
>> pluginManagement makes sense, but how would you add profiles to it? Or
>> would you need to add the profile information in the child poms?
> Yes, if you add/override plugin configuration which does not apply to
> the whole project but just to some modules, you should add it there.
> Just give it a try, I cannot test for you without an MCVE.
>
>>> BTW, if you can fork the original repo for me and just add enough
>>> commits to reproduce your situation, I can take a closer look.
>>> Currently, I have to speculate based on the information I have, which
>>> is less than ideal.
>> I know it's not ideal but I can't share a public fork at the moment.
> Read again, please. I suggested to fork the *original* Kryo repo and add
> just enough Maven config to reproduce the problem. I did not request a
> fork of your internal repo.
>
> See also: https://urldefense.com/v3/__https://stackoverflow.com/help/mcve__;!!GqivPVa7Brio!I33SLOUHJDyw501pJqgBSwasyq6ssvEwjlRRV8KzLHXmYUdFnDHeebMVhPNWw7G5$
>
> --
> Alexander Kriegisch
> https://urldefense.com/v3/__https://scrum-master.de__;!!GqivPVa7Brio!I33SLOUHJDyw501pJqgBSwasyq6ssvEwjlRRV8KzLHXmYUdFnDHeebMVhFSbdbdO$
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: testExcludes/Includes to compile test with different java version

Alexander Kriegisch-2
Hi Julia.

With the MCVE I can see what is going on and also what is going wrong.
But before I make a suggestion or send you a PR, I think we need to
clarify a misunderstanding:

In my first message I was wondering why you wanted mutual exclusivity
and not JDK 14 compilation and tests being a superset of JDK < 14. You
insisted on mutual exclusivity against my recommendation. But now in
your description I see that you seem to describe a behaviour which is
more like the superset thing I had in mind, e.g. for JDK 14 you also
compile the other tests, not just the JDK 14 test you wish to run.

And indeed, when I tried to run the Kryo tests, all except one of the
original (upstream) tests also run fine on JDK 14. Only one of them
fails, SerializationCompatTest. But that is just because you added one
default serializer. This was easy to fix, see commit @7781a952 [1].
Funny enough, UnsafeByteBufferInputOutputTest passes, even though an
exception occurs in method testByteBufferOutputWithPreallocatedMemory.
But there is a try-catch around it, making the test pass. I think it
would be better to fix Kryo to use the appropriate DirectByteBuffer
constructor for newer JDK versions, but this is beyond the scope of our
little chat here.

So what I suggest is to not just run a single test on JDK 14 but to run
all tests, just like you compile all tests.

Now let me explain what went wrong in your build configuration: You have
the profiles jdk8ge and jdk14ge, and *both* of them are active at the
same time under JDK 14 due to the auto-activation conditions you chose.
So far, so good. But that means that their configurations are not
mutually exclusive, as you said you would make them, but they merge into
one. The effective POM shows something like this for the compiler
plugin:

<execution>
  <id>default-testCompile</id>
  <phase>test-compile</phase>
  <goals>
    <goal>testCompile</goal>
  </goals>
  <configuration>
    <release>14</release>
    <compilerArgs>
      <arg>--enable-preview</arg>
    </compilerArgs>
    <testIncludes>
      <testInclude>jdk14/**</testInclude>
    </testIncludes>
    <testExcludes>
      <testExclude>jdk14/**</testExclude>
    </testExcludes>
    <source>1.8</source>
    <target>1.8</target>
    <encoding>utf-8</encoding>
  </configuration>
</execution>

So first you include package jdk14, then you exclude it. Surprisingly,
all tests get compiled anyway, I have no idea why. Maybe the include
just wins in Maven Compiler.

But now there is a similar effect in Surefire:

<execution>
  <id>default-test</id>
  <phase>test</phase>
  <goals>
    <goal>test</goal>
  </goals>
  <configuration>
    <includes>
      <include>jdk14/**</include>
    </includes>
    <argLine>--enable-preview</argLine>
    <excludes>
      <exclude>jdk14/**</exclude>
    </excludes>
  </configuration>
</execution>

Here the in- vs. exclusion has the effect that no tests are run, as you
said. Here obviously the include means that *only* what is included is
considered for a test run, but then you exclude the same thing again,
resulting in zero tests to be run.

So how do you solve that?

Variant 1: You use <configuration combine.self="override"> in the JDK 14
profile for both the Compiler and Surefire plugins and just remove the
corresponding includes, i.e. JDK 14 is the normal case. See commit
@59b013e8 [2].

Variant 2: You do it the other way around and say: Compile and run all
tests is the default and for JDK < 14 you override with excludes. This
way you would not have to configure anything special for JDK 14 except
for the --enable-preview switch and the <release> tag.

By the way, in the root POM is another profile 'until-java11' with
activation condition <jdk>[1.5,11)</jdk>, excluding certain Java 11
tests. I tried to run a build on JDK 8 or JDK 9 with Kryo master, but it
does not even compile because it uses Java 10+ API calls. So maybe
Kryo's build configuration is outdated already. But that's just another
strange thing about that project. I will just assume that anything below
JDK 11 is irrelevant to you, even though you have created a Java 8+
profile. Or does your own real project fork off of another Kryo branch
which is not the master?

[1] https://github.com/kriegaex/kryo/commit/7781a952d2f61766329743c49ea6ca9464920152
[2] https://github.com/kriegaex/kryo/commit/59b013e8bbd25d4fde7a8d6d4f211350ef6bff80
--
Alexander Kriegisch
https://scrum-master.de


Julia Boes schrieb am 02.09.2020 19:32 (GMT +07:00):

> Here's the MCVE fork
>
> https://github.com/oracle/kryo/tree/records
>
> I followed your suggestion and moved the compiler config to the
> relevant children's poms (pom-main, pom-versioned). Compilation works
> as expected now.
>
> To recap: RecordSerializerTest (t) requires jdk 14 --enable-preview
> for compilation and test run.
>
> $ mvn clean && mvn install
>
> with jdk-14.0.1 compiles t with --enable-preview and all other tests
> without the flag
>
> with jdk-11.0.8 compiles all tests but t Similarly, I tried to set
> executions for the test goal to achieve the following:
>
>   1. with jdk-14.0.1 runs t with --enable-preview and all other tests
>      without the flag
>
>   2. with jdk-11.0.8 runs all tests but t
>
> Result:
>
>   2. works fine with the current configuration, but
>
>   1. runs *no* tests at all. I inspected the effective pom and can see
>      that the profile for <jdk11 from the parent pom is inherited, but
>      I'm not sure if that's the problem.

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: testExcludes/Includes to compile test with different java version

Alexander Kriegisch-2
I added another sample commit:

https://github.com/kriegaex/kryo/commit/c1d8729748ddb0e6367d440bed57f58aa64d534a

Quoting the commit comment:

Move Surefire configuration to root POM and streamline

Now only the Compiler plugin configuration for test compilation is
duplicated in submodules kryo and kryo5.

There are two mutually exclusive profiles for versions 11-13 vs. 14+
now, so configuration override is no longer necessary.

I think you can easily adjust that to your needs if in your branch you
have other version ranges, such as 5-8, 9-13, 14+ or 8-13, 14+.

An open question is how you could actually, like you tried right at the
beginning, also configure Maven Compiler in the root POM without making
Maven trigger compilation for the root POM itself. But I did not try to
find out. I am not a Maven expert either, not even a professional
programmer. As an agile coach I just play with software development in
my sparetime. I am sure someone else can help you better there than I.

Cheers
--
Alexander Kriegisch
https://scrum-master.de


Alexander Kriegisch schrieb am 03.09.2020 11:56 (GMT +07:00):

> Hi Julia.
>
> With the MCVE I can see what is going on and also what is going wrong.
> But before I make a suggestion or send you a PR, I think we need to
> clarify a misunderstanding:
>
> In my first message I was wondering why you wanted mutual exclusivity
> and not JDK 14 compilation and tests being a superset of JDK < 14. You
> insisted on mutual exclusivity against my recommendation. But now in
> your description I see that you seem to describe a behaviour which is
> more like the superset thing I had in mind, e.g. for JDK 14 you also
> compile the other tests, not just the JDK 14 test you wish to run.
>
> And indeed, when I tried to run the Kryo tests, all except one of the
> original (upstream) tests also run fine on JDK 14. Only one of them
> fails, SerializationCompatTest. But that is just because you added one
> default serializer. This was easy to fix, see commit @7781a952 [1].
> Funny enough, UnsafeByteBufferInputOutputTest passes, even though an
> exception occurs in method testByteBufferOutputWithPreallocatedMemory.
> But there is a try-catch around it, making the test pass. I think it
> would be better to fix Kryo to use the appropriate DirectByteBuffer
> constructor for newer JDK versions, but this is beyond the scope of our
> little chat here.
>
> So what I suggest is to not just run a single test on JDK 14 but to run
> all tests, just like you compile all tests.
>
> Now let me explain what went wrong in your build configuration: You have
> the profiles jdk8ge and jdk14ge, and *both* of them are active at the
> same time under JDK 14 due to the auto-activation conditions you chose.
> So far, so good. But that means that their configurations are not
> mutually exclusive, as you said you would make them, but they merge into
> one. The effective POM shows something like this for the compiler
> plugin:
>
> <execution>
>   <id>default-testCompile</id>
>   <phase>test-compile</phase>
>   <goals>
>     <goal>testCompile</goal>
>   </goals>
>   <configuration>
>     <release>14</release>
>     <compilerArgs>
>       <arg>--enable-preview</arg>
>     </compilerArgs>
>     <testIncludes>
>       <testInclude>jdk14/**</testInclude>
>     </testIncludes>
>     <testExcludes>
>       <testExclude>jdk14/**</testExclude>
>     </testExcludes>
>     <source>1.8</source>
>     <target>1.8</target>
>     <encoding>utf-8</encoding>
>   </configuration>
> </execution>
>
> So first you include package jdk14, then you exclude it. Surprisingly,
> all tests get compiled anyway, I have no idea why. Maybe the include
> just wins in Maven Compiler.
>
> But now there is a similar effect in Surefire:
>
> <execution>
>   <id>default-test</id>
>   <phase>test</phase>
>   <goals>
>     <goal>test</goal>
>   </goals>
>   <configuration>
>     <includes>
>       <include>jdk14/**</include>
>     </includes>
>     <argLine>--enable-preview</argLine>
>     <excludes>
>       <exclude>jdk14/**</exclude>
>     </excludes>
>   </configuration>
> </execution>
>
> Here the in- vs. exclusion has the effect that no tests are run, as you
> said. Here obviously the include means that *only* what is included is
> considered for a test run, but then you exclude the same thing again,
> resulting in zero tests to be run.
>
> So how do you solve that?
>
> Variant 1: You use <configuration combine.self="override"> in the JDK 14
> profile for both the Compiler and Surefire plugins and just remove the
> corresponding includes, i.e. JDK 14 is the normal case. See commit
> @59b013e8 [2].
>
> Variant 2: You do it the other way around and say: Compile and run all
> tests is the default and for JDK < 14 you override with excludes. This
> way you would not have to configure anything special for JDK 14 except
> for the --enable-preview switch and the <release> tag.
>
> By the way, in the root POM is another profile 'until-java11' with
> activation condition <jdk>[1.5,11)</jdk>, excluding certain Java 11
> tests. I tried to run a build on JDK 8 or JDK 9 with Kryo master, but it
> does not even compile because it uses Java 10+ API calls. So maybe
> Kryo's build configuration is outdated already. But that's just another
> strange thing about that project. I will just assume that anything below
> JDK 11 is irrelevant to you, even though you have created a Java 8+
> profile. Or does your own real project fork off of another Kryo branch
> which is not the master?
>
> [1]
> https://github.com/kriegaex/kryo/commit/7781a952d2f61766329743c49ea6ca9464920152
> [2]
> https://github.com/kriegaex/kryo/commit/59b013e8bbd25d4fde7a8d6d4f211350ef6bff80
> --
> Alexander Kriegisch
> https://scrum-master.de
>
>
> Julia Boes schrieb am 02.09.2020 19:32 (GMT +07:00):
>
>> Here's the MCVE fork
>>
>> https://github.com/oracle/kryo/tree/records
>>
>> I followed your suggestion and moved the compiler config to the
>> relevant children's poms (pom-main, pom-versioned). Compilation works
>> as expected now.
>>
>> To recap: RecordSerializerTest (t) requires jdk 14 --enable-preview
>> for compilation and test run.
>>
>> $ mvn clean && mvn install
>>
>> with jdk-14.0.1 compiles t with --enable-preview and all other tests
>> without the flag
>>
>> with jdk-11.0.8 compiles all tests but t Similarly, I tried to set
>> executions for the test goal to achieve the following:
>>
>>   1. with jdk-14.0.1 runs t with --enable-preview and all other tests
>>      without the flag
>>
>>   2. with jdk-11.0.8 runs all tests but t
>>
>> Result:
>>
>>   2. works fine with the current configuration, but
>>
>>   1. runs *no* tests at all. I inspected the effective pom and can see
>>      that the profile for <jdk11 from the parent pom is inherited, but
>>      I'm not sure if that's the problem.

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: testExcludes/Includes to compile test with different java version

frauboes
In reply to this post by Alexander Kriegisch-2
Hi Alexander,

Thanks for looking into this again.

> So what I suggest is to not just run a single test on JDK 14 but to run
> all tests, just like you compile all tests.

I had originally expected more errors when compiling/running with JDK 14 but that didn't turn out to be the case - good!

I adopted your last commit (move surefire configuration to root pom and streamline), which is a neat solution. It would be great to do something similar for the compiler plugin but given that I've already tried my luck at that I'm happy with this version.

> By the way, in the root POM is another profile 'until-java11' with
> activation condition <jdk>[1.5,11)</jdk>, excluding certain Java 11
> tests. I tried to run a build on JDK 8 or JDK 9 with Kryo master, but it
> does not even compile because it uses Java 10+ API calls. So maybe
> Kryo's build configuration is outdated already. But that's just another
> strange thing about that project. I will just assume that anything below
> JDK 11 is irrelevant to you, even though you have created a Java 8+
> profile. Or does your own real project fork off of another Kryo branch
> which is not the master?

That's right, the JDK 8+ profile was left over from when I thought kryo was built with JDK 8. That's not the case, it's built with JDK 11.

Thanks again for your help!

Cheers,
Julia


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: testExcludes/Includes to compile test with different java version

Alexander Kriegisch-2
I then suggest to remove the 'until-java11' profile altogether and maybe
use Maven Enforcer in order to make sure that the project is built at
least with JDK 11 (see commit [1]).

I also found out how to move the Surefire config back into the root POM
(see commit [2]). I must have been blind before not to see that the
plugin configurations should to into the <pluginManagement> sections of
each profile instead of declaring the plugins as active in the root POM.
Now there is no more duplication and all modules actually having tests
get the correct configuration automatically.

If you were happy with the previous version already, I am expecting a
major endorphin flash now. ;-)


[1] https://github.com/kriegaex/kryo/commit/d6545ce323264f29e054bf3190fd03b7da91b8cc

[2] https://github.com/kriegaex/kryo/commit/40d5c5ad3f2ea74f28b3f91e9555a2a335e68b2b

--
Alexander Kriegisch
https://scrum-master.de


Julia Boes schrieb am 03.09.2020 22:11 (GMT +07:00):

>> So what I suggest is to not just run a single test on JDK 14 but to run
>> all tests, just like you compile all tests.
>
> I had originally expected more errors when compiling/running with JDK 14 but
> that didn't turn out to be the case - good!
>
> I adopted your last commit (move surefire configuration to root pom and
> streamline), which is a neat solution. It would be great to do something
> similar for the compiler plugin but given that I've already tried my luck at
> that I'm happy with this version.
>
>> By the way, in the root POM is another profile 'until-java11' with
>> activation condition <jdk>[1.5,11)</jdk>, excluding certain Java 11
>> tests. I tried to run a build on JDK 8 or JDK 9 with Kryo master, but it
>> does not even compile because it uses Java 10+ API calls. So maybe
>> Kryo's build configuration is outdated already. But that's just another
>> strange thing about that project. I will just assume that anything below
>> JDK 11 is irrelevant to you, even though you have created a Java 8+
>> profile. Or does your own real project fork off of another Kryo branch
>> which is not the master?
>
> That's right, the JDK 8+ profile was left over from when I thought kryo was
> built with JDK 8. That's not the case, it's built with JDK 11.

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: testExcludes/Includes to compile test with different java version

frauboes
> I also found out how to move the Surefire config back into the root POM
> (see commit [2]). I must have been blind before not to see that the
> plugin configurations should to into the <pluginManagement> sections of
> each profile instead of declaring the plugins as active in the root POM.
> Now there is no more duplication and all modules actually having tests
> get the correct configuration automatically.

This is great, much neater to have all the config back in the root pom.

I learnt a few things here about maven, thanks for your help again!

Cheers,
Julia


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]