Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [m2e-dev] Bug 548948 - m2e ignores the 'Exclude Test Code' checkbox

Hello,

I am happy to help with any concerns. To clearly 'experience' the problem you can use the test project I wrote here:

https://github.com/karypid/m2e-core-tests/tree/bug548948/org.eclipse.m2e.tests/projects/548948_test_scope_jdt_setting

If you run maven from command-line in this test project, you will see the expected behaviour (note the profile activation):

$ mvn verify -Pexec-scenarios
...
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ project-with-launch-configs ---
[INFO] Building jar: /home/karypid/d/wc.git/git.eclipse.org/m2e/548948_test_scope_jdt_setting/project-with-launch-configs/target/project-with-launch-configs-0.0.1-SNAPSHOT.jar
[INFO] 
[INFO] --- exec-maven-plugin:1.6.0:exec (main-class-in-regular-with-test-scope) @ project-with-launch-configs ---
LaunchRegularMain loading main.sources.LaunchRegularMain: OK!
LaunchRegularMain loading    test.sources.LaunchTestMain: OK!
LaunchRegularMain loading    main.sources.DepRegularMain: OK!
LaunchRegularMain loading       test.sources.DepTestMain: OK!
[INFO] 
[INFO] --- exec-maven-plugin:1.6.0:exec (main-class-in-regular-with-runtime-scope) @ project-with-launch-configs ---
LaunchRegularMain loading main.sources.LaunchRegularMain: OK!
LaunchRegularMain loading    test.sources.LaunchTestMain: NOOOOOOOOOOOOOOO :-(
LaunchRegularMain loading    main.sources.DepRegularMain: OK!
LaunchRegularMain loading       test.sources.DepTestMain: NOOOOOOOOOOOOOOO :-(
[INFO] 
[INFO] --- exec-maven-plugin:1.6.0:exec (main-class-in-test-with-test-scope) @ project-with-launch-configs ---
LaunchTestMain loading main.sources.LaunchRegularMain: OK!
LaunchTestMain loading    test.sources.LaunchTestMain: OK!
LaunchTestMain loading    main.sources.DepRegularMain: OK!
LaunchTestMain loading       test.sources.DepTestMain: OK!
[INFO] 
[INFO] --- exec-maven-plugin:1.6.0:exec (main-class-in-test-with-runtime-scope) @ project-with-launch-configs ---
Error: Could not find or load main class test.sources.LaunchTestMain
Caused by: java.lang.ClassNotFoundException: test.sources.LaunchTestMain
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary for 548948_test_scope_jdt_setting 0.0.1-SNAPSHOT:
[INFO] 
[INFO] 548948_test_scope_jdt_setting ...................... SUCCESS [  0.008 s]
[INFO] project-with-shared-test-code ...................... SUCCESS [  1.231 s]
[INFO] project-with-shared-runtime-code ................... SUCCESS [  0.062 s]
[INFO] project-with-launch-configs ........................ SUCCESS [  1.070 s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
...

There are 4 launch configuration that replicate the maven-exec-plugin stuff inside the pom.xml:

$ grep ATTR_EXCLUDE_TEST_CODE project-with-launch-configs/*.launch
project-with-launch-configs/main-class-in-regular-with-runtime-scope.launch:    <booleanAttribute key="org.eclipse.jdt.launching.ATTR_EXCLUDE_TEST_CODE" value="true"/>
project-with-launch-configs/main-class-in-regular-with-test-scope.launch:    <booleanAttribute key="org.eclipse.jdt.launching.ATTR_EXCLUDE_TEST_CODE" value="false"/>
project-with-launch-configs/main-class-in-test-with-runtime-scope.launch:    <booleanAttribute key="org.eclipse.jdt.launching.ATTR_EXCLUDE_TEST_CODE" value="true"/>
project-with-launch-configs/main-class-in-test-with-test-scope.launch:    <booleanAttribute key="org.eclipse.jdt.launching.ATTR_EXCLUDE_TEST_CODE" value="false"/>


If you import the test project into your Eclipse using the currently released M2E 1.15 and then try the launch configurations you will see that they do not behave according to JDT classpath settings. Instead they use the 'heuristic' getArtifactScope() to populate the classpath giving different results.

If you launch a nested workspace with M2E 1.16-SNAPSHOT (including my fix) you will see that these launch configurations now set the classpath to what it should be and therefore behave exactly like the respective versions launched via the maven-exec-plugin.

The new code kicks in only when ATTR_EXCLUDE_TEST_CODE is present in the launch configuration. Otherwise it reverts to calling getArtifactScope() to heuristically determine the scope.    

Personally (as explained in Bugzilla) I do not like this, but I left in place anyway. In my original patch I had removed it (I was removing more code lines than I was adding which for me is even better).

JDT now has explicit mechanisms to define what code is "test scope" and what code is "runtime scope". It also provides UI to explicitly control the desired scope (test/runtime) for a launch configuration. Heuristics are no longer necessary (and in fact confusing).

Either way, I'm happy to discuss any concerns in more detail and implement any alternative ideas. My only desire is that eventually M2E has "some" way to "do the right thing" and launch with the defined classpath (and not what it *thinks* should be the classpath).
On Thursday, 9 April 2020, 11:00:30 BST, Mickael Istria <mistria@xxxxxxxxxx> wrote:




On Thu, Apr 9, 2020 at 12:23 AM Alexandros Karypidis <akarypid@xxxxxxxx> wrote:
Hello,

Hi, 

I've raised and submitted a patch for this a while back but it was never reviewed. It's been driving me nuts that I manually build m2e to patch the issue on my Eclipse. I'm really hoping someone can review the patch and merge the fix to master so that it eventually gets released?

Thanks for those contributions and sorry they got ignored so far!
Sending a mail here is indeed a good way to revive interest here, good thing you did it!

_______________________________________________
m2e-dev mailing list
m2e-dev@xxxxxxxxxxx
To unsubscribe from this list, visit https://www.eclipse.org/mailman/listinfo/m2e-dev


Back to the top