I have a maven project with 4 subprojects, let's say the following structure:
Main
|- core (jar)
|- webapp1 (war)
|- webapp2 (war)
|- webapp3 (war)
The three webapp subprojects depends on core subproproject. So the poms are like:
Main (pom.xml):
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>myGroup</groupId>
<artifactId>MyArtifact</artifactId>
<version>1.0</version>
<packaging>pom</packaging>
<properties>
</properties>
<repositories>
</repositories>
<modules>
<module>core</module>
<module>webapp1</module>
<module>webapp2</module>
<module>webapp3</module>
</modules>
...
</project>
Core (pom.xml):
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>core</artifactId>
<packaging>jar</packaging>
<parent>
<groupId>MyGroup</groupId>
<artifactId>MyArtifact</artifactId>
<version>1.0</version>
</parent>
...
</project>
And web app poms are like this:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>webapp1</artifactId>
<version>1.1.0-A1</version>
<packaging>war</packaging>
<parent>
<groupId>MyGroup</groupId>
<artifactId>MyArtifact</artifactId>
<version>1.0</version>
</parent>
<dependencies>
<dependency>
<groupId>MyGroup</groupId>
<artifactId>core</artifactId>
<version>1.0</version>
</dependency>
</dependencies>
...
</project>
Everything worked fine during months when i execute 'mvn package' on the project's root folder and deploy the wars being generated.
But now i want to deploy an Ear instead of separate War files so i added a subproject called earproject. With the following pom.xml:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>earproject</artifactId>
<packaging>ear</packaging>
<parent>
<groupId>MyGroup</groupId>
<artifactId>MyArtifact</artifactId>
<version>1.0</version>
</parent>
<build>
<pluginManagement>
<plugins>
<plugin>
<artifactId>maven-ear-plugin</artifactId>
<version>2.10.1</version>
<configuration>
<finalName>EarName</finalName>
<version>5</version>
<generatedDescriptorLocation>${basedir}/src/main/applicatio/META-INF</generatedDescriptorLocation>
<modules>
<webModule>
<groupId>MyGroup</groupId>
<artifactId>webapp1</artifactId>
<bundleFileName>webapp1.war</bundleFileName>
<contextRoot>/webapp1</contextRoot>
</webModule>
<webModule>
<groupId>MyGroup</groupId>
<artifactId>webapp2</artifactId>
<bundleFileName>webapp2.war</bundleFileName>
<contextRoot>/webapp2</contextRoot>
</webModule>
<webModule>
<groupId>MyGroup</groupId>
<artifactId>webapp3</artifactId>
<bundleFileName>webapp3.war</bundleFileName>
<contextRoot>/webapp3</contextRoot>
</webModule>
</modules>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
<dependencies>
<dependency>
<groupId>MyGroup</groupId>
<artifactId>core</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>MyGroup</groupId>
<artifactId>webapp1</artifactId>
<type>war</type>
<version>1.0</version>
</dependency>
<dependency>
<groupId>MyGroup</groupId>
<artifactId>webapp2</artifactId>
<type>war</type>
<version>1.0</version>
</dependency>
<dependency>
<groupId>MyGroup</groupId>
<artifactId>webapp3</artifactId>
<type>war</type>
<version>1.0</version>
</dependency>
</dependencies>
</project>
Whith this configuration when i run 'mvn clean' and 'mvn package' the ear file is generated but the war files inside the ear file contains an invalid old version of the core.jar. If i check target directories on webapp projects the War files has a right core.jar version. It seems like EAR packaging uses an old version of the jar that is in my mvn repository, but i don't know why, because on the separate war files maven puts the recently created core.jar.
Why is this happening? Do i need to specify anything more on earproject's pom.xml?
I think the problem you are describing can be solved easily. In appearance Maven ear plugin is getting the core jar file from the repository instead of the new compiled one. I don't know the reason of this plugin's behaviour but I found this issue long time ago.
You should install your jar libraries in the local repository by using the following command
mvn clean install
instead of
mvn package
which only generates the artifacts