You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by Julia Boes <ju...@oracle.com> on 2020/09/02 12:32:31 UTC

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

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: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
>

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


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

Posted by Julia Boes <ju...@oracle.com>.
> 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: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


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

Posted by Alexander Kriegisch <al...@kriegisch.name>.
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: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


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

Posted by Julia Boes <ju...@oracle.com>.
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: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


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

Posted by Alexander Kriegisch <al...@kriegisch.name>.
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: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


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

Posted by Alexander Kriegisch <al...@kriegisch.name>.
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: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org