How to do "maven clean install -U" in IDEA?

已回答

NOTE:  Per recommendation from JetBrains support my project has modules (each used to be an Eclipse project) with their own POMs and build to their own deployables / repository targets.  Therefore, each module has its own set of Lifecycle goals in the Maven tab.  Mentioning it just in case it is relevant.

By googling I found two possible solutions, but I had no luck with either.  

1) To create a new Lifecycle goal in the module's Lifecycle entry of the Maven tool that does "maven clean install -U".  The objective here is to make sure that maven does an update of its dependencies automatically when this target is used (instead of requiring that I manually do 1-clean, 2-ReloadAllMavenProjects, 3-Install steps separately).

2) Execute "maven clean install -U" in the Terminal tool, but for some weird reason IDEA does not expose its instance of maven in the Terminal.  Worse... it drops me at the root of the project and not in the subdirectory for the module, so I would have to chdir to it every time by hand... annoying.

 

This has to be a very common issue when using Maven inside of IDEA, and is quite crippling.  Any hints?

 

0

Hi Bruno Genovese You can try to create a Maven Run/Debug configuration under Run | Edit Configurations | + | Maven and specify clean install -U in the Run field:

0

Thank you very much Egor, that works quite well.

An additional (minor) question:  The new targets appear to get added to the top of the list in the order created.  I will have a lot of them and I will need to execute them in a specific order to ensure that the dependencies all update correctly.  Is it possible to choose the order that they show in?

(for example, in this initial list I would likely build bottom to top... but I need to place core-lib between core-services and bom-pom-master).

Or even better, is there a way to create a build list that executes a group of those targets in a specified order?  (although my gut tells me that even though I don't know much about those tools... from what I read it seems that the job might be better suited to github or jenkins than IDEA)

 

 

 

0

Please try using Compound run configuration:

0

Looked very promising, but Compound is placing items in the list in alphabetic order, I don't control the order of building. 

In the previous example... it would end up building rest-db-common before rest-db-common-api, which is exactly backwards since rest-db-common depends on rest-db-common-api and unless the API is built first rest-db-common might not grab the latest (not yet built!) version of the API from the repository. 

0

It looks like configurations ordering is not supported for Compaund run configuration. I can recommend two solutions:

- Re-order run configurations on the left side of the Run/Debug Configurations dialog by drag&drop.

- Create a dummy run configuration and add your Maven goals here as before launch tasks:

Then run the configuration.

0

Thank you very much - I believe you solved a problem that has been bugging me for months and nobody (not even prior formal support tickets) was able to help with before. Builds appear to be working as desired now, including both hard and soft dependencies.

I had to create a BuildMain class with a main() that simply displays "Build complete" for this, and I needed some very minor tweaks to the Before launch targets, but it seems to work exactly as desired.

For a sanity check, could you confirm this is what you meant? Although it appears to work, I'd like to make sure this is exactly what you intended.

In the screenshots:

  • bom-pom-master is the maven bill of materials project that specifies dependencies and versions shared by every other project.
  • core-lib is a traditional library jar.
  • core-services is a Spring Boot application.  Builds into a JAR that launches from command line or a windows service.
  • rest-* modules are REST services.  Each builds into a WAR that the application will call.  The rest-*-api are the corresponding library JARs used by both the REST service and the calling app to represent the JSON objects transferred.
  • web-assets is a trivial web application containing resources that are used by every web application (for example the logo, common images, etc).
  • web-fiq is a web application that relies on everything from before, either as a direct dependency or because it makes calls to those other things.

0

The configuration looks fine.

0

请先登录再写评论。