I want to share my log4j property file with other modules within a project. I found out that maven-remote-resource plugin is one of the solution, but I have some problems using it.
The log4j property file is intended to be used only on test, so the tests on all module will reference the same log4j file.
The following is the structure of my project and submodules.
parent-module
-module_A
-src
-test
-properties
-log4j.properties
pom.xml
-module_B
-src
-main
-java
-src
-test
-java
pom.xml
-module_C
-src
-main
-java
-src
-test
-java
pom.xml
-module_D
-src
-main
-java
-src
-test
-java
pom.xml
pom.xml
The pom on "module_A" (the one to share resource, the log4j.properties) is as follows:
<build>
<resources>
<resource>
<directory>${basedir}/src/test/resources/</directory>
<includes>
<include>*.properties</include>
</includes>
</resource>
</resources>
<pluginManagement>
<plugins>
<plugin>
<artifactId>maven-remote-resources-plugin</artifactId>
<version>1.5</version>
<executions>
<execution>
<goals>
<goal>bundle</goal>
</goals>
</execution>
</executions>
<configuration>
<includes>
<include>**/*</include>
</includes>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
and on the pom of parent module, I added the module_a to the dependency list and call the remote resource plugin
<dependency>
<groupId>com.myproject</groupId>
<artifactId>module_A</artifactId>
<version>${project.version}</version>
<scope>provided</scope>
</dependency>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-remote-resources-plugin</artifactId>
<version>1.5</version>
<configuration>
<resourceBundles>
<resourceBundle>com.myproject:module_A:${project.version}</resourceBundle>
</resourceBundles>
<attachToMain>false</attachToMain>
<attachToTest>true</attachToTest>
</configuration>
<executions>
<execution>
<goals>
<goal>process</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
When I tried to do maven clean install on the whole project, each individual module doesn't see the log4j.properties. But if I move the remote-resource to every individual sub module pom, they can see the property.
Is there a way to share the log4 property by declaring once on the parent pom?
I would suggest to make the Module_A a default jar which contains the resources in
src/main/resources
...nothing needed to be declared or configured. Only put the properties into thesrc/main/resources
directory..everything will be packaged into a ja file..And add the above module as a test dependency like:
in each module which needs the configuration. Than you have the properties on the test class path and it will work...