2012-02-16 77 views
0

我有一个Maven项目有几个模块,自定义文件作为依赖

这些模块之一产生自定义,二进制文件。我需要这个文件作为另一个模块的输入。

我想要做的是取得这个文件作为依赖关系,在一个蚂蚁脚本的帮助下在其他模块中使用它。

我尝试了很多与Maven Assembly插件和依赖关系:复制的依赖插件,但没有成功

感谢您的任何建议

回答

2

我有我的一个项目非常类似的要求。我想在这里合成它,我希望这能帮助你:

比方说,该项目的结构如下:

projectfoo (pom) 
    |- module1 (your binary dependency) 
    L module2 (the module that needs your dependency) 

让我们先从projectfoo POM:

<groupId>com.dyan.sandbox</groupId> 
<artifactId>projectfoo</artifactId> 
<version>0.0.1</version> 
<packaging>pom</packaging> 

<modules> 
    <module>module1</module> 
    <module>module2</module> 
</modules> 

易....

现在模块1:

<parent> 
    <groupId>com.dyan.sandbox</groupId> 
    <artifactId>projectfoo</artifactId> 
    <version>0.0.1</version> 
</parent> 

<groupId>com.dyan.sandbox.projectfoo</groupId> 
<artifactId>module1</artifactId> 
<version>0.0.1</version> 
<packaging>pom</packaging> 

<build> 
    <plugins> 
     <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-assembly-plugin</artifactId> 
      <version>2.2</version> 
      <executions> 
       <execution> 
        <id>make-your-resource</id> 
        <goals> 
         <goal>single</goal> 
        </goals> 
        <phase>package</phase> 
        <configuration> 
         <descriptors> 
          <descriptor>src/main/assembly/resources.xml</descriptor> 
         </descriptors> 
        </configuration> 
       </execution> 
      </executions> 
     </plugin> 
    </plugins> 
</build> 

...和描述符文件(的src/main /组装/ resources.xml中):

<assembly> 
    <id>resources</id> 
    <formats> 
     <format>zip</format> 
    </formats> 
    <includeBaseDirectory>false</includeBaseDirectory> 
    <fileSets> 
     <fileSet> 
      <directory>src/main/resources/</directory> 
      <outputDirectory>.</outputDirectory> 
     </fileSet> 
    </fileSets> 
</assembly> 

我这里假设你以前生成的二进制资源或那种方式和存储在src/main/resources。上面的代码只是创建资源的zip文件,这是缓解它作为module2中maven依赖项的注入的必要步骤。

所以,现在我们只需要这个压缩神器模块2添加作为一个依赖:

<groupId>com.dyan.sandbox.projectfoo</groupId> 
<artifactId>module2</artifactId> 
<version>0.0.1</version> 

<dependencies> 
    <dependency> 
     <groupId>com.dyan.sandbox.projectfoo</groupId> 
     <artifactId>module1</artifactId> 
     <version>0.0.1</version> 
     <classifier>resources</classifier> 
     <type>zip</type> 
     <scope>provided</scope> 
    </dependency> 
</dependencies> 

...最后与Maven的依赖,插件解压,最好在classpath模块2的(目标/班):

<build> 
    <plugins> 
     <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-dependency-plugin</artifactId> 
      <executions> 
       <execution> 
        <id>unpack-your-resource</id> 
        <goals> 
         <goal>unpack-dependencies</goal> 
        </goals> 
        <phase>generate-resources</phase> 
        <configuration> 
         <!-- unzip the resources in compilation folder --> 
         <outputDirectory>${project.build.directory}/classes</outputDirectory> 
         <includeArtifactIds>module1</includeArtifactIds> 
         <excludeTransitive>true</excludeTransitive> 
        </configuration> 
       </execution> 
      </executions> 
     </plugin> 
    </plugins> 
</build> 

...这就是它!

Yannick。

+0

我会尽快测试这个,但它看起来不错:-)已经非常感谢 – Yves 2012-02-20 07:07:47

+0

让我知道它;)。 – Yanflea 2012-02-20 07:58:15

+0

这适用于我的情况。谢谢 – Yves 2012-03-21 12:07:50