Hi,

I have a multi module project with two modules(mod1 and mod2). mod2 depends
on mod1 so added this as a dependency to the mod2/pom.xml.

I have a couple of plug-ins (maven-enforce-plugin) enabled in individual
module's pom.xml. All of them are tied to ( generate-resources) lifecycle
less than compile lifecycle.

And when I am trying to run *mvn generate-resources* it fails saying that
cannot resolve  com.test:mod1:jar:1.0-SNAPSHOT. I haven't ran any previous
build so this jar was not available in either local repo or remote repo.

This works fine if we ran any goals greater than or equal to compile since
the compiled classes directory added to classpath.

Is there any way that we can avoid dependency resolution before compile
phase, so that we can execute pre-compile tasks independently?

Any help or suggestions will be greatly appreciated.

Version of Maven used is 2.2.1

Below is my project structure.

myp
|-- mod1
|   |-- pom.xml
|   `-- src
|       `-- main
|           `-- java
|               `-- com
|                   `-- test
|                       |-- A.java
|                       `-- B.java
|-- mod2
|   |-- pom.xml
|   `-- src
|       `-- main
|           `-- java
|               `-- com
|                   `-- test
`-- pom.xml

Parent pom.xml

<?xml version="1.0"?>
<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/maven-v4_0_0.xsd";>
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.test</groupId>
  <artifactId>myp</artifactId>
  <packaging>pom</packaging>
  <version>1.0-SNAPSHOT</version>
  <name>myp Maven Multi Project</name>
  <dependencyManagement>
    <dependencies>
      <dependency>
        <groupId>com.test</groupId>
        <artifactId>mod1</artifactId>
        <version>1.0-SNAPSHOT</version>
      </dependency>
      <dependency>
        <groupId>com.test</groupId>
        <artifactId>mod2</artifactId>
        <version>1.0-SNAPSHOT</version>
      </dependency>
    </dependencies>
  </dependencyManagement>
  <modules>
    <module>mod1</module>
    <module>mod2</module>
  </modules>
  <properties>
    <tomcat.base>/home/test/apache-tomcat-5.5.23</tomcat.base>
    <tomcat.home>${tomcat.base}</tomcat.home>
    <tomcat.version>5.5.23</tomcat.version>
  </properties>
</project>

mod1/pom.xml

<?xml version="1.0"?>
<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/maven-v4_0_0.xsd";>
  <modelVersion>4.0.0</modelVersion>
  <artifactId>mod1</artifactId>
  <packaging>jar</packaging>
  <version>1.0-SNAPSHOT</version>
  <name>Module 1</name>
  <parent>
    <groupId>com.test</groupId>
    <artifactId>myp</artifactId>
    <version>1.0-SNAPSHOT</version>
  </parent>
  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
  </dependencies>
</project>

mod2/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/maven-v4_0_0.xsd";>
  <modelVersion>4.0.0</modelVersion>
  <artifactId>mod2</artifactId>
  <packaging>jar</packaging>
  <version>1.0-SNAPSHOT</version>
  <name>Module 2</name>
  <parent>
    <groupId>com.test</groupId>
    <artifactId>myp</artifactId>
    <version>1.0-SNAPSHOT</version>
  </parent>
  <dependencies>
    <dependency>
      <groupId>com.test</groupId>
      <artifactId>mod1</artifactId>
      <version>1.0-SNAPSHOT</version>
    </dependency>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
  </dependencies>
<build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-enforcer-plugin</artifactId>
        <version>1.0</version>
        <executions>
          <execution>
            <id>Validate</id>
            <phase>generate-resources</phase>
            <goals>
              <goal>enforce</goal>
            </goals>
            <configuration>
              <rules>
                <requireProperty>
                  <property>tomcat.base</property>
                  <message>Tomcat Base Needed</message>
                </requireProperty>
                <requireProperty>
                  <property>tomcat.home</property>
                  <message>Tomcat Home Needed</message>
                </requireProperty>
                <requireProperty>
                  <property>tomcat.version</property>
                  <message>Tomcat Version Needed</message>
                </requireProperty>
              </rules>
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
</project>


Thanks and Regards,
Deepesh

Reply via email to