I have maven plugin installed for my eclipse of version (Oxygen).
I have the following added to my pom.xml -
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-eclipse-plugin</artifactId>
<configuration>
<downloadSources>true</downloadSources>
<downloadJavadocs>true</downloadJavadocs>
</configuration>
</plugin>
I can go to my project and click Maven -> Update Project and it updates it.
Still it is not treated as a java project though. When I am trying add a new package or a class, I get the error "Source folder is not a Java project.". Could someone please provide me pointers? Appreciate any help in advance!
You can first create a java project and right-click the project at Package-Explorer view, select Configure>Convert to Maven Project, then you can use maven dependency.
Related
I would like to use existing step definition classes coming from maven jar dependency.
My cucumber tests works if ran from Runner Class (with glue to packages) & mvn CLI. But the
problem is with IntelliJ Cucumber plugin for the steps which are coming from jar. In feature file steps that I am using from the jar are shown as "Undefined step reference:...". I am not even able to run directly from feature file.
Is there a way I can configure cucumber plugin to use stepdefinations from classloader/jar?
Posting the solution worked for Me:
Use IntelliJ 2020.1 +
In cucumber run configuration : select jar manifest for classpath
Deploy the Jar with source jar as well to Nexus as below
You can simple do this by adding maven-source-plugin plugin to your build
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>3.2.0</version>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
In other project add dependency and confirm source is downloaded from repo
File -> Project Structure -> Libraries -> Select the Artifact -> Sources , Make sure it's not in red.
Update IntelliJ to use latest version, for me IntelliJ version 2019 did not work but 2020.1 was able to find the step definitions.
PS: I use Java8 with Lambda exp and I can confirm it works.
Updating Intellij from version 2019.3 to 2022.2 solved the issue without changing anything else.
My project is in Java 8
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<release>11</release>
</configuration>
</plugin>
</plugins>
</build>
What is the point of using maven in intellij if it dose not work without setting the correct JDK under various intellij options?
What I mean is that now with intellij I have to set the JDK in 3 different places.
File->Setting->Build->Compiler
File->Project Structure->Project
File->Project Structure->Modules
While I aspect expect that when i compiler on the right side where are the maven options it works just by watching the pom file.
i think that depends on what type of project you want to make but personally i find maven nice to use because you can set up several actions in the pom file (for example when compiling Less files, excluding them from the build and just using the resulting css files).
another feature would be the easy way to add dependency's from the maven rep http://mvnrepository.com/
I have created a web application in spring mvc and now i have to migrate the project to an offline machine but when i imported the project in my eclipse(offline) then it got stuck on "Importing Maven Projects" and also it is showing an error in my pom.xml file at tag :-
<plugins>
<plugin> // shows error over here
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
I also read something about mvn dependency:go-offline so I tried it but couldn't exactly understand that where it saves the dependencies?
So, is there a way through which i could import the project in the offline environment?
As pointed out by #Thomas, the only way to build a project which needs external dependencies with Maven is to copy the repository in the target environment. Build your project on an online environment, then copy your .m2 folder in the offline one. The build will then find all required libraries locally.
With mvn dependency:go-offline you tell maven to download all the needed plugin dependencies in your local repository.
Normally in eclipse when you press ctrl + click on a class file eclipse takes it to the source code .
I have a few jars in my projet that i imported through maven . But when i click on a class to see its source not Eclipse tells me that the source of the class is not available . I have tried and give the exact source to the jar with the attach external jar option in the window that opens but no help .
I have no idea why this is happening .
Download source code of jar files through maven using this:
mvn dependency:sources
If you want to download for specific jar
mvn dependency:sources -DincludeArtifactIds=name_of_jar
Or, in your eclipse plugin in pom, specify it
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-eclipse-plugin</artifactId>
<configuration>
<downloadSources>true</downloadSources>
<downloadJavadocs>true</downloadJavadocs>
</configuration>
</plugin>
</plugins>
</build>
Run mvn:eclipse:eclipse after above from command line
I have a Java-Groovy Eclipse project that I build with Maven. I have added the Maven Groovy plugin to the pom.xml such that I can build/test the Java and Groovy sources on the command-line using Maven.
I would like to have some way to automatically generate the Eclipse .project and .classpath files from my pom.xml. If I run mvn eclipse:eclipse it seems to assume that it's a Java project, so there's no way to (for example) run the tests in src/main/groovy from within Eclipse.
I'm using the STS Eclipse distribution, which includes support for Groovy/Grails. All I'm missing is a way to automatically create the appropriate .classpath and .project files.
Thanks!
P.S. I know IntelliJ is better, but I don't have a license
Here is configuration I found that works when Java calls Groovy code
and when Groovy calls Java code fitting good within groovy eclipse IDE plugin (nature).
There is no need for additional source folders for groovy. It just works!
Using:
mvn clean install eclipse:clean eclipse:eclipse
<dependencies>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-all</artifactId>
<version>2.0.4</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
<compilerId>groovy-eclipse-compiler</compilerId>
<verbose>true</verbose>
<extensions>true</extensions>
</configuration>
<dependencies>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-eclipse-compiler</artifactId>
<version>2.7.0-01</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-eclipse-plugin</artifactId>
<version>2.9</version>
<configuration>
<additionalProjectnatures>
<projectnature>org.eclipse.jdt.groovy.core.groovyNature</projectnature>
</additionalProjectnatures>
<sourceIncludes>
<sourceInclude>**/*.groovy</sourceInclude>
</sourceIncludes>
</configuration>
</plugin>
</plugins>
</build>
You should try the Groovy-Eclipse m2eclipse integration. It is available here:
http://dist.codehaus.org/groovy/distributions/greclipse/snapshot/e3.6/
With this installed, your maven projects will be automatically configured as groovy-eclipse projects when you import them into your workspace.
If you would like to create a Groovy project just by calling mvn eclipse:eclipse you have to configure your project. As follows a snippet how you configure your maven eclipse plugin so that your project becomes a Groovy project in Eclipse. That snippet must go into your projects pom.xml by the way.
...
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-eclipse-plugin</artifactId>
<configuration>
<additionalProjectnatures>
<projectnature>org.eclipse.jdt.groovy.core.groovyNature</projectnature>
</additionalProjectnatures>
<sourceIncludes>
<sourceIncludes>**/*.groovy</sourceIncludes>
</sourceIncludes>
</configuration>
</plugin>
</plugins>
</build>
...
When you now call mvn eclipse:eclipse maven creates the .project and .classpath files. .project contains the new project nature what makes it a Groovy project and .classpath contains the */*.groovy* what makes Eclipse treating any file that ends on .groovy as a source file.
Please see also http://maven.apache.org/plugins/maven-eclipse-plugin/examples/provide-project-natures-and-build-commands.html
There is another best way to create maven groovy project. Please follow below steps:
Navigate to https://start.spring.io/ from your browser.
Select project as maven and language as groovy as shown below.
Select other options as per your build requirement like packaging, java version and project name.
Now click on Generate radio button at the bottom and a maven groovy project will be downloaded.
Open Eclipse and import the downloaded maven project and it's ready to use for your groovy scripting with maven integration.