m2e does not import dependency from profile - eclipse

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".
POM dependencies
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

Related

Gatling Error: Could not find or load main class Engine

I installed the latest IntelliJ idea, latest maven 3.6.3, Java 1.8, set the JAVA_HOME / JRE_HOME env variables. Then generated a Gatling project using mvn archetype:generate -Dfilter=gatling. In summary, I followed the instruction here. I have installed the Scala plugin for IntelliJ idea as well. When I try to run the Gatling engine by right-clicking on the Engine class,
I am getting below error. can someone tell me what's going on here? I tried all the suggestions online, but no luck so far. Thanks
"C:\Program Files (x86)\Java\jdk1.8.0_221\bin\java.exe".....
Error: Could not find or load main class Engine
Process finished with exit code 1
Here is my POM file
<?xml version="1.0" encoding="UTF-8"?>
<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.mycompany.gatling</groupId>
<artifactId>pert-tests</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<encoding>UTF-8</encoding>
<gatling.version>3.2.1</gatling.version>
<gatling-maven-plugin.version>3.0.3</gatling-maven-plugin.version>
</properties>
<dependencies>
<dependency>
<groupId>io.gatling.highcharts</groupId>
<artifactId>gatling-charts-highcharts</artifactId>
<version>${gatling.version}</version>
</dependency>
<dependency>
<groupId>io.gatling</groupId>
<artifactId>gatling-app</artifactId>
<version>${gatling.version}</version>
</dependency>
<dependency>
<groupId>io.gatling</groupId>
<artifactId>gatling-recorder</artifactId>
<version>${gatling.version}</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>io.gatling</groupId>
<artifactId>gatling-maven-plugin</artifactId>
<version>${gatling-maven-plugin.version}</version>
</plugin>
</plugins>
</build>
</project>
David MontaƱo... after manually marking src/test/scala as Test Sources Root, I got "Error:(11, 18) illegal cyclic inheritance" as mentioned by Rasika
I just found that scala 2.13.1 is not compatible with gatling. I removed scala 2.13.1 from global libraries list and added scala 2.12.10. Tests working fine now. Here are the steps
Right click project folder in IntelliJ and choose 'Open Module Settings'
Under 'Platform Settings' select 'Global Libraries'
Here, remove scala-sdk-2.13.1 and add scala-sdk-2.12.10
Rebuild the module
It worked for me when I manually marked the src/test/scala as Test Sources Root and rebuild the project.
Mark as Test Sources Root
It should be picked up automatically by IntelliJ but it wasn't the case.
Tied both :
marked the src/test/scala as Test Sources Root and rebuild the project.
Mark as Test Sources Root
And
Under 'Platform Settings' select 'Global Libraries'
Here, remove scala-sdk-2.13.1 and add scala-sdk-2.12.10
then works.

Eclipse Maven dependency jar grayed out, can't import classes from it

I'm helping a friend configure a maven project with m2eclipse for the first time. We're both pretty unfamiliar with it and are encountering an issue where even though a dependency jar is showing up with packages in it under "maven dependencies" in the Project directory, if we try to import anything from any of that jar's packages, it can't find the class.
I noticed that the jars that are having issues are gray and not as opaque as the rest of the jars that are working.
What's strange is if you hover of the class name in the import, it shows a brief description of the class (from the documentation in the jar!) but it won't let me import it. All the other maven dependencies can be imported fine. Any ideas? We can't seem to even find what the darker icon means.
Also, the pom.xml is dead simple:
http://maven.apache.org/xsd/maven-4.0.0.xsd">
4.0.0
<groupId>com.something.portal.test</groupId>
<artifactId>PortalFrontEndTests</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>PortalFrontEndTests</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<!-- Selenium -->
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>2.53.1</version>
</dependency>
<!-- TestNG -->
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.11</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
I'm not sure what I'm missing here
open your pom.xml file
check for the name of the grayed out jar file
change
<scope>test</scope>
to
<scope>compile</scope>
I found the issue. It was because I had the class in the source directory instead of the test directory and both of the maven dependencies had been marked as "Visible only to test"
I had the same problem when i used the <scope>test</scope> in the maven pom.
It seems as if the newer Eclipse/Java versions do have a new Attribute :
<classpathentry kind="src" output="target/test-classes" path="src/test/java/...">
<attributes>
<attribute name="test" value="true"/>
</attributes>
</classpathentry>
This should be enabled in the Java Build Path Settings:
Image showing "Containts test sources" option from build path menu
After enabling this i got rid of all the compiler errors.
check for your dependency scope in POM file
compile, provided, system and test these were the available test
test -> compile would change your dependencies from grey to white.
If your dependency is for test scope then that dependency is not available for normal use in application whereas compile scope sets that dependency in class path of your project.
I am not sure on the grayed out part. If this is the feature because it suggest that Testing class should be under /test rather /src.
However, solution to your problem is scope of plugin, change it to compile and you will be good to go.
i.e. replace test with compile:
<scope>test</scope>
<scope>compile</scope>
That's it. you will not get any error for import testing packages.
Just removing the Scope will work. I tried as the following:
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.8.0-M1</version>
</dependency>
I am also faced the same problem
set scope to compile or remove scope
open maven dependencies
right click on dependency and click download resources

When automating Eclipse's "Export as Feature", Maven/Tycho doesn't see my plugin

I have a plugin and a feature project in my workspace. When I export the feature manually via File > Export As > Feature everything works well. I'm trying to write an automatic plugin building and exporting script to get rid of this chore. I converted feature project to Maven project and filled pom.xml with:
<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>MyProject</groupId>
<artifactId>NMGDBPluginFeature</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>eclipse-feature</packaging>
<properties>
<tycho-version>0.22.0</tycho-version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<repositories>
<repository>
<id>eclipse-luna</id>
<layout>p2</layout>
<url>http://download.eclipse.org/releases/luna</url>
</repository>
</repositories>
<build>
<plugins>
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>tycho-maven-plugin</artifactId>
<version>${tycho-version}</version>
<extensions>true</extensions>
</plugin>
</plugins>
</build>
</project>
However script throws:
[ERROR] Cannot resolve project dependencies:
[ERROR] Software being installed: NMGDBPluginFeature.feature.group 1.0.0.qualifier
[ERROR] Missing requirement: NMGDBPluginFeature.feature.group 1.0.0.qualifier requires 'GDBFifoBlocks [1.0.0.gdbfifoblocks]' but it could not be found
How could that happen? I thought pom.xml uses feature.xml of project, doesn't it? What is a proper configuration?
So far, your configuration looks good. However you currently only have an automated build for your feature, but not the for the plugin. Unlike the Eclipse export wizard, eclipse-feature only processes the feature.xml - and it expects that the referenced plugins are built elsewhere.
So what you need to do is to set up a Maven reactor which includes both an eclipse-feature and an eclipse-plugin project. Here is how you do this:
Make your current pom.xml the parent POM: Change the packaging to pom, adapt the artifactId to something which makes sense (e.g. MyProject.parent), and move the pom.xml into a new general project in your workspace.
Add a pom.xml in the root of the feature project:
<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>MyProject</groupId>
<artifactId>MyProject.parent</artifactId>
<version>1.0.0-SNAPSHOT</version>
<relativePath>relative/path/to/parent/project</relativePath>
</parent>
<artifactId>NMGDBPluginFeature</artifactId>
<packaging>eclipse-feature</packaging>
</project>
Add another pom.xml in the root of the plugin project, which is the same as the one above except for the artifactId - this needs to be the same as the plugin's Bundle-SymbolicName - and the packaging which needs to be eclipse-plugin.
Include the plugin and feature projects in the Maven reactor by adding a <modules> section in the parent POM with the paths to these projects:
<modules>
<module>relative/path/to/plugin/project</module>
<module>relative/path/to/feature/project</module>
</modules>
Note that the paths need to be adapted so that they are correct for the project locations on disk (which may be different to what is shown in the Eclipse workspace). The paths need to be relative, so they probably start with ../.
Now you can trigger a Maven build on your parent POM, and the feature should be able to resolve the reference to your plugin. In Eclipse, you can trigger the Maven build from the context menu of the pom.xml file. Or, if you also convert the parent project to a Maven project, the you can also run Maven builds from the context menu of the project root.

Pom packaged parent module containing Maven Tycho eclipse plugin project as a sub-module

Rough Project structure is as follows:
Parent module
<groupId>groupId</groupId>
<artifactId>Module-Parent</artifactId>
<packaging>pom</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>Parent Project</name>
<modules>
<module>Module1</module>
<module>Module2</module>
<module>PluginModule3</module>
</modules>
<properties>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
</properties>
PluginProject pom.xml
<parent>
<groupId>groupId</groupId>
<artifactId>Module-Parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>PluginProject</artifactId>
<name>Plugin Project</name>
<packaging>eclipse-plugin</packaging>
<dependencies>
<dependency>
<groupId>Module2groupID</groupId>
<artifactId>module2</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
// tycho dependencies included
Now since the packaging of the parent and sub-module are different. I am not able to refer the parent classes in my code using eclipse and the maven dependencies/libraries are also not considered. However I am able to build all the modules successfully using maven and Tycho respectively (if I don't refer any classes from parent project).
All the libraries related to Maven are getting removed by itself from the build path of the plugin-project as soon as the eclipse-pluginentry added in sub module pom.xml.
Please help me how to resolve my parent class references in my plugin-project.
OSGi doesn't support references from bundles to non-bundle libraries.
So if you want to re-use classes from your other modules in the build, they also need to be OSGi bundles, and you need to set the appropriate exports and inports in the OSGi bundle manifests.

Eclipse with maven workspace dependency - packaged war contain folder instead of jar

I'm using Eclipse Kepler SR2 with m2e.
I have a web project that depends on a jar.
When I use "Run as -> Maven Build..." with goal package and "Check Workspace artifacts" is checked, then the lib folder in the target contains a folder with the name of the dependency jar, instead of the jar itself. The packaged war also contains a folder instead of a jar. However, when deploying to tomcat with m2e, the jar is deployed correctly.
I use maven-war-plugin version 2.4.
This is my WAR pom:
<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.modelity.loans</groupId>
<artifactId>loans-parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>loans-web</artifactId>
<packaging>war</packaging>
<dependencies>
<dependency>
<groupId>com.modelity.loans</groupId>
<artifactId>loans-core</artifactId>
<version>0.0.1-SNAPSHOT</version>
<type>jar</type>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.4</version>
</plugin>
</plugins>
</build>
</project>
And this is the artifact coordinates of the dependency jar:
<parent>
<groupId>com.modelity.loans</groupId>
<artifactId>loans-lib</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>loans-core</artifactId>
<packaging>jar</packaging>
I've looked at the debug output of the maven package goal. When the war plugin is processing the jars, it says
[DEBUG] Processing: loans-core-0.0.1-SNAPSHOT.jar
without indicating the jar has been copied.
Later on in the log I see:
adding directory WEB-INF/lib/loans-core-0.0.1-SNAPSHOT.jar/
I've tried both embedded maven (3.0.4) and external maven (3.0.5).
My colleague uses kepler SR1, and experience the same problem.
I think I've covered it all. Would be happy for some advise, couldn't find any reported bug about it.
Thanks,
Lior
Try installing the jar as its own maven-controlled artifact:
mvn install:install-file -Dfile=my.jar -DgroupId=com.mycorp -DartifactId=my-jar -Dversion=1.0 -Dpackaging=jar
And then define it as a maven dependency for your war
now we have 2018 and the problem still exists in eclipse v2018-09. Maven Dependencies which exist in the workspace are exploded into WEB-INF/lib folder.
Found this old bug report https://issues.jboss.org/browse/JBIDE-22157 regarding this behaviour.
Solution is to disable "dependency resolution from workspace projects" in maven project settings.
regards,
Markus