如何在maven-remote-resources-plugin中使用<includes> / <excludes> </excludes> </includes>

时间:2012-09-28 07:52:52

标签: maven filtering maven-resources-plugin

我试图按照this示例使用maven-remote-resources-plugin来选择性地共享多个maven模块之间的公共资源,并且我很难有选择地将资源导入到工作

我正在尝试使用<includes><excludes>元素,如下所示。我没有在doco中看到过这些插件中提到的插件,但是eclipse在命令完成时将它们作为有效选项提供,并且当我运行pom时我没有遇到任何错误。到目前为止,我无法让<includes><excludes>对导入的资源产生任何影响

我的pom的相关部分是;

共享资源

<build>
  <plugins>
    <plugin>
       <artifactId>maven-remote-resources-plugin</artifactId>
       <executions>
         <execution>
           <goals>
             <goal>bundle</goal>
           </goals>
         </execution>
       </executions>
       <configuration>
         <includes>
           <include>**/*</include>
         </includes>
       </configuration>
     </plugin>
  </plugins>
</build>

<dependencies>
  <dependency>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-remote-resources-plugin</artifactId>
    <version>1.3</version>
  </dependency>
</dependencies>

资源消费者

<build>
 ...
  <plugins>
    <plugin>
       <groupId>org.apache.maven.plugins</groupId>
       <artifactId>maven-remote-resources-plugin</artifactId>
       <version>1.3</version>
       <configuration>
         <resourceBunldes>
           <resourceBundle>myApp:myApp_sharedresources:${project.version}</resourceBundle>
         </resourceBundles>
         <outputDirectory>${project.build.outputDirectory}</outputDirectory>
         <includes>
           <include>theOnlyResourceIWant.properties</include>
         </includes>
       </configuration>
       <executions>
         <execution>
           <goals>
             <goal>process</goal>
           </goals>
           <phase>generate-resources</phase>
         </execution>
       </executions>
     </plugin>
  </plugins>
</build>

<dependencies>
  <dependency>
    <groupId>myApp</groupId>
    <artifactId>myApp_sharedresources</artifactId>
    <version>1.0</version>
  </dependency>
</dependencies>

我尝试过很多<includes><excludes>的组合,但到目前为止都没有影响。

所以,是

<includes></includes>

<excludes></excludes>

maven-remote-resources-plugin配置的有效元素,以及如何使用它们? 我可以合理地将资源分成单独的maven模块,但这可能会创建大量的单文件maven模块并添加大量额外的xml,所以我想尽可能避免使用它。

我真的不想开始讨论插件源代码,但这是下一步。

2 个答案:

答案 0 :(得分:2)

我为我正在导入的共享资源使用临时目录并对其进行过滤。

下面的远程资源插件配置。这会将所有共享资源复制到项目的临时目录中。将attached设置为false意味着它们不会包含在您的最终项目工件中,这使您有机会使用Maven的常规资源处理选择要包含的工件。

<plugin>
<artifactId>maven-remote-resources-plugin</artifactId>
<configuration>
  <resourceBundles>
    <resourceBundle>myApp:myApp_sharedresources:${project.version}</resourceBundle>
  </resourceBundles>
  <attached>false</attached>
  <outputDirectory>${project.build.directory}/shared-resources</outputDirectory>
</configuration>
<executions>
   <execution>
     <goals>
       <goal>process</goal>
     </goals>
     <phase>generate-resources</phase>
   </execution>
 </executions>
</plugin>

资源定义。当maven-resource-plugin运行时(默认情况下,它与jars / wars / ears的生命周期绑定),它将使用共享资源目录以及普通src/main/resources目录。你需要定义它们。 (如果需要,您也可以启用资源过滤。)

<resources>
  <resource>
     <directory>${project.build.directory}/shared-resources</directory>
     <includes>
       <include>theOnlyResourceIWant.properties</include>
     </includes>
  </resource>
  <resource>
     <directory>${basedir}/src/main/resources</directory>
  </resource>
</resources>

我建议将共享目录设为${project.build.directory}的子目录,这样clean生命周期才能正常运行。

答案 1 :(得分:0)

要为格式为“#{expr}”(Ruby样式)启用过滤器分隔符,请在插件配置中添加以下内容:

<plugin>
    <artifactId>maven-remote-resources-plugin</artifactId>
    <version>1.3</version>
    <executions>
      <execution>
        <id>process-remote-resources</id>
        <goals>
          <goal>process</goal>
        </goals>
        <configuration>
          <filterDelimiters>
            <filterDelimiter>#{*}</filterDelimiter>
          </filterDelimiters>
          [...]
        </configuration>
      </execution>
    </executions>
  </plugin>

检查this link以获取参考