【问题标题】:Merge .properties files with Apache shades plugin使用 Apache shades 插件合并 .properties 文件
【发布时间】:2016-03-19 05:09:36
【问题描述】:

我正在尝试使用 shades 插件合并我的一个 OSGi 包中的 2 个依赖项(openwebbeans-impl、openejb-core)中出现的 openwebbeans.properties 文件。 我按照阴影文档 我的配置如下https://maven.apache.org/plugins/maven-shade-plugin/examples/resource-transformers.html#AppendingTransformer

   <plugin>
         <groupId>org.apache.maven.plugins</groupId>
         <artifactId>maven-shade-plugin</artifactId>
         <version>2.3</version>
         <executions>
               <execution>
                    <phase>package</phase>
                    <goals>
                        <goal>shade</goal>
                    </goals>
                    <configuration>
                        <transformers>
                            <transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
                                   <resource>META-INF/openwebbeans/openwebbeans.properties</resource>
                             </transformer>
                        </transformers>
                    </configuration>
                </execution>
           </executions>
    </plugin>

但是当我尝试 mvn clean install 时它失败并出现以下错误

[INFO] --- maven-shade-plugin:2.3:shade (default) @ tomee ---
[ERROR] The project main artifact does not exist. This could have the following
[ERROR] reasons:
[ERROR] - You have invoked the goal directly from the command line. This is not
[ERROR]   supported. Please add the goal to the default lifecycle via an
[ERROR]   <execution> element in your POM and use "mvn package" to have it run.
[ERROR] - You have bound the goal to a lifecycle phase before "package". Please
[ERROR]   remove this binding from your POM such that the goal will be run in
[ERROR]   the proper phase.
[ERROR] - You removed the configuration of the maven-jar-plugin that produces the main artifact.
[INFO] ------------------------------------------------------------------------

有人能告诉我我的配置有什么错误吗? 这样做的正确方法是什么?

编辑

根据 struberg 提供的答案,我的尝试似乎不适用于 openwebebans 上下文。但我仍然想知道合并属性文件的正确方法是什么。或者如何解决这个问题。

【问题讨论】:

  • 我的猜测:在打包插件之前调用了 shade 插件。解决这个问题的最好方法是在&lt;plugins&gt;-部分中提到这两个插件,您首先提到包装插件,然后是shade-plugin。当插件绑定到同一阶段时,Maven 将自上而下评估它们。
  • @RobertScholte 它是 pom 中的最后一个插件。我什至改变了顺序并把它放在第一位。但没有运气

标签: maven maven-shade-plugin


【解决方案1】:

棘手的部分是我们在每个文件中都有一个“configuration.ordinal”属性。这定义了信息“合并”的顺序。稍后将在较低的序数配置之上应用更高的序数值。因此,来自更高序号配置的配置设置将保持不变。

阅读更多https://struberg.wordpress.com/2010/09/21/flexible-configuration-for-modular-systems/

【讨论】:

  • 那篇文章解释得很好。所以我认为虽然我的问题仍然有效,但它不适用于 openwebbeans 上下文。非常感谢您的链接。我支持答案:) 我也编辑了这个问题。
  • 是否可以创建自己的阴影转换器并使用 PropertyLoader.getProperties(..) 并将结果写入新文件?
  • 这是个好建议。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-09-19
  • 2018-12-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-08-16
相关资源
最近更新 更多