Using Different Properties Files for Runnable Jars, Maven Eclipse Using Different Properties Files for Runnable Jars, Maven Eclipse jenkins jenkins

Using Different Properties Files for Runnable Jars, Maven Eclipse


This is what I came up with. I would love to know other approaches or the best way to do this however. Being totally new to all of this.

  1. Create separate executions in the same plugin. Note: They must be assigned different <id> values.
  2. Each <execution> can be configured differently. To rename the resources that you are including use the <transfomer>implementation = implementation="org.apache.maven.plugins.shade.resource.IncludeResourceTransformer">.
  3. To exclude resources that are not needed (in my case, other properties files) use <transformer> implementation = "org.apache.maven.plugins.shade.resource.DontIncludeResourceTransformer">. This is more nicety than necessity. Why bundle up unneeded files in your jar?
  4. Make sure each <execution> has a different <finalName> so that the resulting jars don't overwrite each other.

Here is my pom file.

<build>    <plugins>        <plugin>            <groupId>org.apache.maven.plugins</groupId>            <artifactId>maven-shade-plugin</artifactId>            <version>2.2</version>            <executions>                <execution>                    <id>ID1</id>                    <phase>package</phase>                    <goals>                        <goal>shade</goal>                    </goals>                    <configuration>                        <transformers>                            <transformer                                implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">                                <mainClass>com.foo.dashboard.bar.Runner</mainClass>                            </transformer>                            <transformer                                implementation="org.apache.maven.plugins.shade.resource.IncludeResourceTransformer">                                <resource>defaultconfig.properties</resource>                                <file>src/main/resources/defaultconfig_1.properties</file>                            </transformer>                            <transformer                                implementation="org.apache.maven.plugins.shade.resource.DontIncludeResourceTransformer">                                <resource>defaultconfig_2.properties</resource>                            </transformer>                        </transformers>                        <finalName>FooBar1</finalName>                    </configuration>                </execution>                <execution>                    <id>ID2</id>                    <phase>package</phase>                    <goals>                        <goal>shade</goal>                    </goals>                    <configuration>                        <transformers>                            <transformer                                implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">                                <mainClass>com.foo.dashboard.bar.Runner</mainClass>                            </transformer>                            <transformer                                implementation="org.apache.maven.plugins.shade.resource.IncludeResourceTransformer">                                <resource>defaultconfig.properties</resource>                                <file>src/main/resources/defaultconfig_2.properties</file>                            </transformer>                            <transformer                                implementation="org.apache.maven.plugins.shade.resource.DontIncludeResourceTransformer">                                <resource>defaultconfig_1.properties</resource>                            </transformer>                        </transformers>                        <finalName>FooBar2</finalName>                    </configuration>                </execution>            </executions>        </plugin>    </plugins></build>

I know this is not the final answer since this set up yields multiple jar files and I was originally looking for a solution that would give me only the jar file associated with a specific properties file, not all of the jar files from all of the properties files.

So I'm still taking suggestions on how to improve this solution so that the build would only a yield a single jar.