eclipse-m2e / m2e-core

Eclipse Public License 2.0
113 stars 116 forks source link

Maven Update Project wipes out Run Configuration #1872

Open SiKing opened 1 month ago

SiKing commented 1 month ago
  1. Start with any Maven project. I used simple mvn archetype:generate -DarchetypeGroupId=org.apache.maven.archetypes -DarchetypeArtifactId=maven-archetype-quickstart.
  2. Open the project in Eclipse.
  3. Select the test and Run As > JUnit Test.
  4. The previous step will have created a Run Configuration. Open this Configuration: Run > Run Configurations.
  5. Under the Environment tab create an environment variable. Anything will do: this=that.
  6. Apply and Close. Go back a verify the environment variable still exists!
  7. Back in the Package Explorer, right click on the project > Maven > Update Project. Leave all the default checkboxes and click OK. The project is cleaned and rebuilt.
  8. Go back to the Run Configuration and check the environment variable. It is gone!
  9. I often use VM Arguments, under Arguments tab. These get wiped as well.

If you save the run configuration to disk first, it still gets wiped.

I tried all this with a TestNG run configuration, and this problem does not happen in this case.

This started happening after an update a few months back? So I decided to completely reinstall the latest and greatest:

It is still happening there.

treilhes commented 1 month ago

Hello @SiKing,

The only issue i see here is that the testng configuration isn't updated. https://github.com/eclipse-m2e/m2e-core/blob/master/RELEASE_NOTES.md#262

As a workaround you can disable it in the meantime by launching Eclipse with the JVM system property -Dm2e.process.test.configuration=false.

Another less absolute workaround would be to exclude your tests from surefire/failsafe


<configuration>
  <excludes>
    <exclude>**/MyExcludedTest1.java</exclude>
    <exclude>**/MyExcludedTest2.java</exclude>
  </excludes>
</configuration>
SiKing commented 1 month ago

My issue is that using Maven Update Project wipes my environment settings (and some others) from the Run Configuration. I am sure this started happening only a few months ago. Is this a new feature?

The m2e.process.test.configuration=false setting does what I need.

treilhes commented 1 month ago

Yes it is a new feature in 2.6.2

Surefire/Failsafe plugin configuration propagated to Junit/TestNG launch configuration
The following arguments are supported:
<argLine>,
<environmentVariables>,
<systemPropertyVariables>,
<workingDirectory>,
<enableAssertions>,

Configuration is propagated on unit test launch configuration creation and also when executing maven > update project
SiKing commented 1 month ago

Seems strange for Maven plugin to modify non-Maven files - the run configuration.

In our case, environment variables is how we pass passwords into our code. For obvious reasons, we do not want these in the Surefire configuration.

treilhes commented 1 month ago

For a maven plugin yes but for m2e no It is one of the goal of m2e to propagate maven configuration into eclipse to have the same behaviour between cli and eclipse