Multi module maven project and resolve workspace artifacts problem

I have a problem with getting workspace resolution working while working with a multi module maven project.
Lets say I have 2 Maven modules where A (webapp) depends on B (library).
Everything works while working in IntelliJ, dependencies get resolved while coding and deploying inside application server.

However, when I try to run maven compile or package targets from the Maven Projects Tool window for project B, then everything fails.
If I create a maven run configuration for this target and open this. Then I see the setting "Resolve workspace artifacts", enabling this also solves everything.

Is there some kind of way to always enable this "Resolve workspace artifacts" setting, so I dont need to create run configurations for all those lifecycle targets?

I am using Intellij 12 and maven3.

1 comment

I'll try to answer here and bear with me as my Maven knowledge is pretty fuzzy. Unfortunately you're being blinded by the side effects of using an IDE vs a command line build system. IDEs like IntelliJ try to be smart when they assemble/run your code and save you steps. In your example directly building, WebAppA without first building LibraryB from the comand-line would cause a failure because your LibraryB SNAPSHOT would need to be at least in your local repository for the dependency to be satisfied. The "Resolve workspace artifacts" checkbox works around the flaw by automatically triggering the build for LibraryB prior to invoking Maven on WebAppA since it "knows" the dependency heirarchy. when trying to build from the Maven tool window you are invoking the Maven build system directly on the pom for WebAppA which knows the dependency as at least a prebuilt snapshot in your local repo. The problem is that you probably shouldn't build the pom for the web app directly, rather use a top-level Maven multi-module pom to control the targets your project. This would require a little more working knowledge of Maven where you could define goals to package/deploy/run web-app sub modules. (I've done this years ago with Cargo/Wagon/Tomcat/Jetty plugins and it's pretty cool when you get it to work.) Working in both IntelliJ and Maven can sometimes complicate the issue because you are, in essence, maintaining 2 build systems. There's the built-in Idea build system, and the Maven build system and without keeping the two in sync you will no doubt run into confusion. Building a top-level multi-module pom in Maven is probably to your advantage as it lets you manage the entire project wholistically as you would in Idea while giving you the ability to generate site docs and reports across modules and configure/build different types of packaging. (For Eg. if you wanted a custom installer for your web-app or needed to eventually deploy as a .ear archive.)

0

Please sign in to leave a comment.