Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have a problem with maven assembly plugin.

I have a maven project which use several jars. Each jar contains configuration files. With another project, I use maven assembly plugin to assemble all configurations in unique jar.

All work fine but unfortunately, two files are the same name and the second overwrites the first.

I don't achieve to tell maven to merge the two files instead of overwrite.

Someone knows how to do that ?

Thanks.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
145 views
Welcome To Ask or Share your Answers For Others

1 Answer

The maven-shade-plugin combined with the AppendingTransformer should do what you want.

We use it to merge together the properties files from two zip projects, defined as separate maven modules, into a single zip file. This creates the superset of the files and directories from the two modules and merges together the specified properties file. We also define the module to merge as a dependency of the maven module doing the merge.

Something like this should do the trick:

<plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-shade-plugin</artifactId>
      <version>1.4</version>
      <executions>
        <execution>
          <phase>package</phase>
          <goals>
        <goal>shade</goal>
          </goals>
          <configuration>
        <filters>
          <filter>
            <artifact>groupname:artifactname</artifact>
            <includes>
              <include>**/*</include>
            </includes>
          </filter>
        </filters>
        <transformers>
          <transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
            <resource>propertyfiletomerge.properties</resource>
          </transformer>
        </transformers>
          </configuration>
        </execution>
      </executions>
    </plugin>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...