I have a maven project, 'a', that builds a simple library. The project has an additional source folder that can be optionally included by specifying a named profile. This will do two things:
- Include an additional source folder in the built jar that is otherwise not included
Add a dependency that is needed by this additional source, that is otherwise not needed
<profile> <id>special</id> <dependencies> <dependency> <groupId>com.example</groupId> <artifactId>dependency</artifactId> <version>1.0</version> </dependency> </dependencies> </profile>
There is also a twist. I cannot guarantee that the additional dependency is always available. That means I cannot list it as a dependency that is always included, because in some cases it cannot be resolved so the build will fail. Therefore I only want to include this dependency when the profile is explicitly activated.
Subsequently, I have another project 'b', that has 'a' as a dependency. I want project 'b' to be agnostic to whether 'a' was built with the regular profile or the special profile. Project 'b' uses the maven-dependency-plugin to copy dependencies to a folder:
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>lib</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
What would be the easiest way to make sure project 'b' copies the additional dependency if project 'a' was built with the special profile, but not otherwise? I can make any modifications to project 'a' that I would like, but would prefer not to make modifications to project 'b' unless necessary.
As it stands, with the additional dependency specified as part of a profile, maven never includes it as part of the copy-dependencies - regardless of which profile I built project a with. Ultimately I get a ClassNotFoundException if I run project b having built project a with the special profile.
I will clarify the example if needed. Thanks in advance!