How to ensure that a module build ALWAYS updates the maven repository?
I have a recurring problem that I'm sure has a well known solution in IntelliJ:
- My IntelliJ project (aka ex-Eclipse workspace) has many modules, all relying on Maven.
- Some of the modules generate JARs that should be deployed to the local repository. I'll call these "libraries".
- When I modify library code that is used by another project and test in the IDE everything works, modules that I am working on somehow find the latest version of the library code.
- But I often forget to run a manual maven install of the library before doing the maven install of the modules that use it (like a WAR).
- So when I deploy to a server the WAR contains an obsolete version of the JAR. And since I have a bunch of these WARs to deploy, I often lose hours because of missing that initial maven install for the library. Everything has to be rebuilt and redeployed. Worse, if I was doing a PROD deploy this could leave the whole PROD server down for hours - something completely unacceptable.
So, on to the QUESTION:
What can I do to ensure that every time I build or run a Maven project it always automatically updates the repository? (My knowledge of maven isn't as solid as it should be, please answer in terms that a noob could understand. I suspect this will be some kind of special custom IntelliJ IDEA maven target but I have no idea what or how.)
Please sign in to leave a comment.
>What can I do to ensure that every time I build or run a Maven project it always automatically updates the repository?
If a) in Maven you specify the dependency on a module with sources, i.e. use the maven maven coordinates you are currently have in Maven module pom.xml and b) you have this Maven module imported into the same IDE project - IDE as a dependency will use the module's sources instead of the jar in the local Maven repository.
Another possible option to try is to use the
IDE property, please see https://intellij-support.jetbrains.com/hc/en-us/community/posts/360005958400/comments/360000823520
I am afraid that either I am not understanding your answer or you are not understanding my question.
- Things are working fine when I build/test inside of IntelliJ either as an app with embedded tomcat or deploying to a localhost tomcat server.
- Once the above is done I deploy to a DEV/TEST server on a different box. I do this by grabbing the JAR/WAR from the local repository. (maybe this is the wrong way to do it?!!!)
- But since the repository is ONLY being updated when I select Maven in IntelliJ and double-click on "Install", in the heat of coding/testing I often forget the manual Maven/Install step.
That means that at the time of deploying to DEV/TEST I often grab a JAR/WAR from the repository that was built with an old version of *my* library (not one obtained from a public repository), resulting in a completely corrupt deployment that can only be fixed by wiping the local repository completely and rebuilding every single module for the local repository from scratch... extremely time consuming.
That is why I asked for a way to automatically trigger Maven/Install every time a project is built or run. Can it be done? Or do I need some other tool? (like maybe integrating with gitHub and doing the DEV/TEST build there - no idea how, but I could look it up if that is what I need, or maybe Jenkins... that somebody here said is an automatic build/deploy tool, again a tool I know nothing about yet)
My instincts tell me that IntelliJ IDEA can do it all and result in reliable builds/deploys to DEV/TEST for multiple interrelated modules with complex net of dependencies (some hard like libraries and some soft like REST services)... but I might not even be asking the right question. Anything that points me in the right direction would be welcome, and perhaps later I can improve the question?
I think I understood correctly:
>That means that at the time of deploying to DEV/TEST I often grab a JAR/WAR from the repository that was built with an old version of *my* library (not one obtained from a public repository),
You are saying that when you install the library from one of your Maven projects into a local repository, then it only works (you have the correct version of libraries in the resulted jar/war).
I'm saying that a possible way of solving this is to eliminate using the jar as a dependency and use the module actual sources instead: so then when you build the resulting jar/war - IDE will use not the jar dependencies but module sources as dependencies and will always build the last version of all sources.
To make use of the module dependencies instead of the jar dependencies you can by trying two approaches I posted in previous message. Does this help?