【问题标题】:Disable resource filtering for maven-remote-resources-plugin禁用 maven-remote-resources-plugin 的资源过滤
【发布时间】:2012-10-02 05:05:18
【问题描述】:

我正在尝试使用 maven-remote-resources-plugin 在多模块 maven 项目中跨模块共享大量资源。不幸的是,共享的二进制资源在捆绑过程中被破坏了,大概是通过过滤。

我确信在这个阶段发生了损坏,因为从我的本地存储库中提取共享资源 jar 包含损坏的二进制文件。

有什么可以关闭 maven-remote-resources-plugin 的过滤吗?

目前我的共享资源模块中的 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>

【问题讨论】:

  • 你的意思是maven-remote-resources-plugin?从您的 pom.xml 发布相关的 sn-ps 可能有助于吸引答案。
  • 感谢@DuncanJones,这是正确的。我已经修正了错字并添加了 pom 的相关部分

标签: maven filtering maven-resources-plugin


【解决方案1】:

听起来资源在捆绑过程中被破坏了。由于资源项目只是一个 jar,它作为默认生命周期的一部分执行 resources 插件。尝试将其添加到资源项目的 POM。

<plugin>
    <artifactId>maven-resources-plugin</artifactId>
    <version>2.6</version>
    <executions>
      <execution>
        <id>default-resources</id>
        <configuration>
          <nonFilteredFileExtensions>
            <nonFilteredFileExtension>exe</nonFilteredFileExtension>
            <nonFilteredFileExtension>dontFilterMeEither</nonFilteredFileExtension>
          </nonFilteredFileExtensions>
          [...]
        </configuration>
      </execution>
    </executions>
  </plugin>

docs 描述了默认情况下哪些二进制文件未被过滤;上面的配置将扩展添加到列表中。

【讨论】:

  • 这是一个与我使用的不同的插件(错字已更正),所以请您在上面的配置中填写[...]。
  • user944849 的意思是使用这两个插件,因为 maven-resources-plugin 默认绑定到生命周期。所以可能是 maven-resources-plugin 也损坏了你的文件,所以你应该“保护”你的文件免受两者的影响,并按原样添加上面的配置。
  • 非常感谢@SamuelEUSTACHI。 :-)
【解决方案2】:

你试过了吗:

<plugin>
        <artifactId>maven-remote-resources-plugin</artifactId>
        <version>1.3</version>
        <executions>
          <execution>
            <id>process-remote-resources</id>
            <goals>
              <goal>process</goal>
            </goals>
            <configuration>
              <useDefaultFilterDelimiters>false</useDefaultFilterDelimiters>
              [...]
            </configuration>
          </execution>
        </executions>
      </plugin>

【讨论】:

  • 我试过了,不幸的是二进制文件在捆绑过程中仍然损坏
【解决方案3】:

我们为解决此问题而采取的方法如下。
请注意,我误解了 user944849 的回答,所以我没有对其进行测试,它可能会起作用。

我们使用共享资源 pom 中的资源子句直接在本地存储库中创建了 jar。我认为这是使用 maven-resources-plugin (?)。

然后使用maven-dependency-plugin解压到一个临时目录,并在resource-consumer pom的resources子句中过滤出想要的资源。

共享资源

<build>
  <resources>
    <resource>
      <directory>src/main/resources</directory>
      <filtering>false</filtering>
      <includes>
        <include>**/*</include>
      </includes>
    </resource>
  </resources>
</build>

资源消费者

<build>
  <resources>
    <resource>
      <directory>${project.build.directory}/shared-resources</directory>
      <includes>
        <include>theOnlyOneIWant.properties</include>
      </includes>
    </resource>
  </resources>
  [...]
  <plugins>
    <plugin>
      <artifactId>maven-dependency-plugin</artifactId>
      <version>2.5</version>
      <executions>
        <execution>
          <id>shared-resources</id>
          <goals>
            <goal>unpack-dependencies</goal>
          </goal>
          <phase>generate-resources</phase>
          <configuration>
            <includeGroupIds>myProjectGroup</includeGroupIds>
            <includeArtifactIds>myProjectSharedResources</includeArtifactIds>
            <outputDirectory>${project.build.directory}/shared-resources</outputDirectory>
          </configuration>
        </execution>
      </executions>
    </plugin>
  </plugins>
</build>

这可能不适用于可以使用 maven-remote-resources-plugin 的所有实例,但它对我们有用并解决了二进制资源损坏的问题。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-02-18
    • 2018-02-19
    • 2013-04-11
    • 2012-06-09
    • 2015-08-20
    • 2013-11-20
    • 1970-01-01
    • 2012-09-20
    相关资源
    最近更新 更多