Hi I've parent pom.xml like below.. , say I've 4 modules currently.. But at certain times I might not have all the 4 modules all the time.. Is there any way to make these module(s) (Child projects) optional within root pom.xml. Which means that child project will not be present in the one branch , but will be present in another branch .. I don't want to use multiple root pom.xml's for different branches.. Is it possible?
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>com.xx.xx.correspondence</groupId>
<artifactId>xxHudsonTP</artifactId>
<version>1</version>
<packaging>pom</packaging>
<modules>
<module>xxCastor</module>
<module>cxxYYYCastor</module>
<module>xxCommon</module>
<module>xxxx</module>
</modules>
</project>
Optional dependencies are used when it's not possible (for whatever reason) to split a project into sub-modules. The idea is that some of the dependencies are only used for certain features in the project and will not be needed if that feature isn't used.
Open the dependency POM and find the transitive dependency you want to exclude. Copy groupId and artifactId . In your project POM, underneath your active dependency, enter exclusions and using code completion paste the copied info of the dependency you want to exclude.
In order to exclude these special dependencies from the main project, we can apply Maven's <optional> tag to them. This forces any user who wants to use those dependencies to declare them explicitly. However, it does not force those dependencies into a project that doesn't need them.
You can use profiles, like they did it for example in flex-mojos plugin project:
...
<profiles>
<profile>
<id>minimal</id>
<modules>
<module>flexmojos-parent</module>
<module>flexmojos-sandbox</module>
<module>flexmojos-generator</module>
<module>flexmojos-maven-plugin</module>
<module>flexmojos-super-poms</module>
<module>flexmojos-testing</module>
</modules>
</profile>
<profile>
<id>release</id>
<modules>
<module>flexmojos-parent</module>
<module>flexmojos-sandbox</module>
<module>flexmojos-generator</module>
<module>flexmojos-maven-plugin</module>
<module>flexmojos-super-poms</module>
<module>flexmojos-archetypes</module>
<module>flexmojos-testing</module>
</modules>
</profile>
<profiles>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With