I have come up with this simplified test case of the problem I am experiencing with the very big project I am working on. The important bit is to have some code and its dependency activated only in a specific profile. Here is the POM file to demonstrate it:
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>mytest</groupId>
<artifactId>project1</artifactId>
<version>1.0</version>
<properties>
<src.dir>src/main/java</src.dir>
</properties>
<build>
<sourceDirectory>${src.dir}</sourceDirectory>
</build>
<profiles>
<profile>
<id>fox</id>
<properties>
<src.dir>src/fox/java</src.dir>
</properties>
<dependencies>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.8.1</version>
</dependency>
</dependencies>
</profile>
</profiles>
</project>
And in the directory src/fox/java/project1 relative to the POM I have got this simple class using the jar dependency from the pom:
package project1;
import org.apache.commons.lang3.BooleanUtils;
public class C1 {
public static void main(String[] args) {
System.out.println(BooleanUtils.isTrue(Boolean.FALSE));
}
}
I can build the above project with this command without a problem:
mvn -Pfox package
But I don't know how to properly import this Maven project into Eclipse. The abnormality can be seen if I open its POM in Eclipse and observe it in the "Dependencies" tab. The commons-lang3 jar file does not show there by default. Only if I click on the button "Show inherited dependencies" it comes up with the icon in front of it presumably denoting it was "inherited".
But I don't understand where it could be "inherited from. I also want to add the it shows as a "normal" dependency if I don't use the profiles.
I did specify the profile "fox" at the import time and verified that it was selected in Eclipse. I also tried "Update project" option from Eclipse which did not make a difference.
This in itself would not bother me if it was't a symptom of the bigger problem I am experiencing. In our application a project like in the example is a dependency of another project with WAR packaging. And when such project is deployed to Tomcat running under Eclipse the jar from the picture is not included into the deployment description and naturally the application does not run.
Profiles in dependencies are not activated
https://issues.apache.org/jira/browse/MNG-1388