Maven dependency management and IDE: scope `import`

advertisements

I have a few multi-module maven projects. It's Java EE application, so all of them go to single EAR file eventually, and that's why there is a special separate POM, where all the dependency management is described for 3-rd party dependencies:

<groupId>mygroup</groupId>
<artifactId>my-3rd-party-deps</artifactId>
<version>1.0.0</version>
<packaging>pom</packaging>

It also imports JBoss AS parent POM in it's dependency management section:

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.jboss.as</groupId>
            <artifactId>jboss-as-parent</artifactId>
            <version>7.1.3.Final</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>

Every project has it's own parent, where I describe

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>mygroup</groupId>
            <artifactId>my-3rd-party-deps</artifactId>
            <version>1.0.0</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>

and every sub-module just describe their dependencies without versions.

This works perfectly, when you use command line. All the dependency versions resolved correctly.

But in IDE (I tried IDEA, Eclipse and NetBeans) I get errors.

IDEA

[ERROR] 'dependencies.dependency.version' for org.jboss.spec.javax.ejb:jboss-ejb-api_3.1_spec:jar is missing. @ line 63, column 29 less...

Eclipse

For artifact {org.jboss.spec.javax.ejb:jboss-ejb-api_3.1_spec:null:jar}: The version cannot be empty. (org.apache.maven.plugins:maven-resources-plugin:2.6:resources:default-resources:process-resources)

while the version for org.jboss.spec.javax.ejb:jboss-ejb-api_3.1_spec is in the JBoss AS parent POM.

Why this happens and how can I resolve this to work in IDE without errors?


In your base pom you should have

<modules> <module>subModule</module> </modules>

then in your submodule pom you should have

<parent> <artifactId>something</artifactId> <groupId>something</groupId> <version>something</version> <relativePath>../pom.xml</relativePath> <--Notice the path </parent>

Have you try'ed other scopes besides import?

If you use other scope then import, you should be able to use only the groupId and the artifactId in your submodule. As you had already defined the version and the scope in the base pom. You can override them if you use some other version or scope in your submodule.

Other thing that you could do is in your base pom define a properties

<properties> <project.jboss.artifact>1.5</project.jboss.artifact> </properties>

And in the artifact version (in your submodule pom) you could use the variable

<version>${project.jboss.artifact}</version>