Vscode-java: Maven and Java "auto build" and Maven profiles

Created on 6 Feb 2020  路  4Comments  路  Source: redhat-developer/vscode-java

When you have a POM with multiple profiles, there seems to be no way to tell M2E what profile to build with. It will only build the profile that has "active by default" attached to it. if there is no such profile, the build output is incomplete.

Also, when running MVN build in the terminal on a different profile, the "auto build" may kick in and modify the "target" folder simultaneously with the terminal's MVN execution. This causes many hard-to-diagnose problems, like the "target" folder's contents are incorrect, or the JAR contents is incorrect. I only figured this out when i set my other profile to build to a completely separate "target-xxx" folder.

I can disable Java "auto build" and use the "standard" output folder, and a terminal-based MVN works correctly.

I tried setting the Maven plugins options (e.g. -Pdev), but apparently that does not get used when M2E runs MVN.

I don't really want all my profiles to output to different locations, and I don't want to selectively disable "auto build", so is there a way to tell M2E what profile to use, preferably on a per-folder or per-workspace basis.

Environment
  • Operating System: Windows 10
  • JDK version: JDK 8
  • Visual Studio Code version: 1.41.1
  • Java extension version: 0.55.1
  • Maven for Java: 0.22.1
  • Maven version: 3.6.0
Steps To Reproduce
  1. Have a POM with multiple profiles, e.g. dev and prod, e.g. a JAR package.
  2. Have Java "auto build" enabled.
  3. Have "update configuration" set to automatic.
  4. Have the "dev" profile be "active by default"
  5. Important: to easily observe the issue, the "prod" and "dev" profiles must have some mutually-exclusive content, e.g. the "prod" profile may make minimized JS files that go into the JAR file, and excludes (some of) the files from the "dev" profile, e.g. non-minified JS files.
  6. At this point M2E auto-builds the "dev" profile into "target".
  7. Go to the terminal window and build the "prod" profile via command line.
  8. There will be "interference" with what the "prod" profile does, and the "dev" profile, because "dev" is "active by default" and apparently always gets executed. The most-common outcome is the "prod" execution gets "cleaned" by M2E while it runs the other profile.
  9. Removing "active by default" from "dev" now causes an incomplete build, because any resources etc. that are in the "dev" profile do not execute. This is likely because M2E doesn't have an explicit profile to run (we just deactivated it).
  10. Now if you run the "prod" profile in terminal, everything flows normally.
Current Result
  1. Have to force one of the profiles to be "active by default" so "normal" IDE functions work, e.g. compiled files end up in the "right location".
  2. Have to temporarily disable "auto build" when executing any other profile, then remember to re-enable it afterward :-(
Expected Result
  1. Be able to tell M2E what profile to use when it rebuilds on an auto-build.
  2. Not be forced to have the "makes-IDE-work" profile be active by default.
  3. Honor the Maven Plugins "opts" when it runs maven.
  4. Don't trigger auto-build when the "target" folder changes.
Additional Informations

Is there a way to do this currently?

Maven

Most helpful comment

We are missing a setting in this extension to pass parameters to Maven for the build before the run.

All 4 comments

Be able to tell M2E what profile to use when it rebuilds on an auto-build.

@pyramid-johng you can try to add the following property:

activeProfiles=prod

to /.settings/org.eclipse.m2e.core.prefs

We are missing a setting in this extension to pass parameters to Maven for the build before the run.

Any updates on this? It'd be nice a property to specify the active profile.

I found that seems after updating org.eclipse.m2e.core.prefs. An update project action is also needed to be triggered to make the change active.

Was this page helpful?
0 / 5 - 0 ratings