开发者

maven build dependencies in Eclipse, multiple projects

I have two projects in eclipse, both are maven controlled. A references B and they are on a flat system. What we currently have setup is that we have to a build on B - generate a jar on the system, and A references that jar.

I'd like to change this to be we just have to build A and it will go automatically build B? Can I do this in Maven/eclipse such that I don't have to create some higher project?

I have looked into some of the maven docs - but they just really confuse me :). Thanks for your help.

The pom's look like this

(B)

    <project xmlns="..." xmlns:xsi="..."
 xsi:schemaLocation="...">
 <modelVersion>4.0.0</modelVersion>
 <groupId>com.thetus</groupId>
 <artifactId>irisMDK</artifactId>
 <packaging>jar</packaging>
 <name>irisMDK</name>
 <version>0.1</version>
 <url>...maven.apache...</url>
 <build>
  <sourceDirectory>java/src/main</sourceDirectory>
  <plugins>
   <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>2.1</version>
    <configuration>
     <source>1.6</source>
     <target>1.6</target>
     <testExcludes>
      <exclude>**/*.java</ex开发者_运维问答clude>
     </testExcludes>
    </configuration>
   </plugin>
  </plugins>
  <resources>
   <resource>
    <directory>java/src/main</directory>
   </resource>
  </resources>
 </build>
 <dependencies>
  ...
 </dependencies>
</project>

------ And (A):

 <project xmlns="..." xmlns:xsi="..."
 xsi:schemaLocation="...">
 <modelVersion>4.0.0</modelVersion>
 <groupId>local.b</groupId>
 <artifactId>projectB</artifactId>
 <packaging>jar</packaging>
 <name>B</name>
 <version>RELEASE</version>
 <url>...</url>
 <repositories>
  <repository>
   <id>maven2-repository.dev.java.net</id>
   <name>Java.net Repository for Maven</name>
   <url>...download.java.net/maven...</url>
  </repository>
 </repositories>
 <build>
  <plugins>
                   ...
  </plugins>
  <sourceDirectory>java/src/main</sourceDirectory>
  <testSourceDirectory>java/src/test</testSourceDirectory>
  <resources>
  </resources>
 </build>
 <dependencies>
  <dependency>
   <groupId>local.b</groupId>
   <artifactId>projectB</artifactId>
   <scope>system</scope>
   <version>RELEASE</version>
   <systemPath>${basedir}/../B/target/B-0.1.jar</systemPath>
  </dependency>
 ...
 </dependencies>
 <reporting>
  ...
 </reporting>
</project>

If you could show me an example of how to change ^^^ I would be most grateful!!


Original Answer: The M2Eclipse plugin, if you are not using it already, allows you to do this. Once installed, remove

<systemPath>${basedir}/../B/target/B-0.1.jar</systemPath>

from A's pom.xml and make sure the groupid, artifactid, version match up with what is defined in B's pom.xml

Then right-click on the project, Maven-> Enable Dependency Resolution. The build should now look at B's local project

Edit:

If B's pom.xml looks like this (from your example):

<project xmlns="..." xmlns:xsi="..."
      xsi:schemaLocation="...">
      <modelVersion>4.0.0</modelVersion>
      <groupId>com.thetus</groupId>
      <artifactId>irisMDK</artifactId>
      <packaging>jar</packaging>
      <name>irisMDK</name>
      <version>0.1</version>

      ...
 </project>

In A's pom (which depends on Project B) your dependency should look like:

<project>
...
    <dependencies>
      <!--Attributes of project that this project is dependent upon, as defined in that projects POM -->
      <dependency>
           <groupId>com.thetus</groupId>
           <artifactId>irisMDK</artifactId>
           <version>0.1</version>
      </dependency>
 ...
     </dependencies>
....
</project>

This will tell maven and eclipse that project A explicitly depends on that version of Project B. With M2Eclipse, if you have a matching groupId, artifactId, and version in your workspace and you have "Dependency Resolution" enabled, Project B's contents will automatically be built and included into Project A.

Also, opening the Maven console in eclipse (console view->new console dropdown->new maven console) could help in debugging why project B isn't be picked up by Project A.


Sounds like you want to use a multi-module project, here is a simple tutorial. You would create a parent POM, and have both A and B as children, with A keeping its dependency on B.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜