Grails - adding Maven dependency to Eclipse classpath - java

I've added a Maven dependency into my Grails project, and I'm trying to get that reflected on my Eclipse setup. I've already run grails compile --refresh-dependencies and grails refresh-dependencies (I don't know the difference) but neither got the job done. There are no errors, and I can see that the dependency is correctly reported in grails dependency-report.

I don't know what the difference is, but after running refresh-dependencies using GGTS in Eclipse [project context ("right click") > Grails Tools > Refresh Dependencies], the jars appeared in the classpath.

Related

Intellij - conflicting module versions - how to find source of dependency

I have a groovy class in maven java project. I upgraded the groovy dependency from 2.4.4. to 2.4.11. If I build the project using maven - it works. However, if I build it with IntelliJ - I get this error:
Information:Groovyc: While compiling MyProject: Conflicting module versions. Module [groovy-jsr223 is loaded in version 2.4.11 and you are trying to load version 2.4.4
java.lang.ExceptionInInitializerError.
When I go to project structre -> dependencies, I see: Maven: org.codehaus.groovy:groovy-jsr233:2.4.4.
When I search all my pom.xml fiels for 2.4.4 - there is nothing left - everywhere I have 2.4.11.
I tried rebuilding all with maven, reimporting maven projects in IntelliJ - nothing works.
Where should I look for this dependency? Is there a quick way to track it?
I have found a solution - Maven Helper plugin (https://plugins.jetbrains.com/plugin/7179-maven-helper). It adds "Dependency Analyzer" tab to pom files view.
Many time this trick works for me.
go to maven widget in intellij idea and click on the refresh icon. it should do the magic.

How to import GAE java project (with maven) in Eclipse?

I'm reading this: https://cloud.google.com/java/getting-started/using-forms
and i'd like to import this project in Eclipse from 0, but i'm getting a lot of errors. (Generally any GAE projects).
What are the steps to do this?
Create new Java project, run Maven (?) and so on...
I need to use Mars 2 and have installed jdk 1.7 and 1.8.
THX.
(PS: It works using the guide. So i can run the app on cmd)
Update: errors after AndrĂ¡s Kerekes'solutions
Try to follow these steps:
git clone the whole Getting Started Java repository
run mvn eclipse:eclipse in the top level directory of the cloned repository
import the projects into Eclipse (including the one at the top level: the project is called getting-started-java, you should see it in the Project Explorer) using File > Import... > Maven > Existing Maven Projects
You may see an error dialog about Maven errors, in the Action field, click on the cell and select to option to install the m2e connector for the JDT compiler. This will install a plugin into your Eclipse to bridge M2Eclipse and the JDT, you'll need to restart Eclipse once it finishes.
You may still see Maven errors like Plugin execution not covered by lifecycle configuration: org.apache.maven.plugins:maven-compiler-plugin:3.3:compile (execution: default-compile, phase: compile), which is OK. You dependencies should be set for the project and there should be no compilation error.
Ensure that the project uses JDK8 as it depends on classes that are only available since Java 8 (like java.util.function.Function)
You may want to install the Cloud Tools for Eclipse plugin for additional GAE support.

Maven Error : Maven Project Configuration for Module isn't available

I keep getting this error when I try to compile my code. I have the pom.xml file in my directories but I am not sure if there is something wrong in there. I found only one link on the internet regarding this and that was not my case: Maven project configuration required for module
Error:Maven Resources Compiler: Maven project configuration required for module 'updater' isn't available. Compilation of Maven projects is supported only if external build is started from an IDE.
Here is the content of 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.nothing.updater</groupId>
<artifactId>Updater</artifactId>
<version>1.0-SNAPSHOT</version>
<!--<dependencies>-->
<!--<dependency>-->
<!--<groupId>com.nothing.toolbox</groupId>-->
<!--<artifactId>Toolbox</artifactId>-->
<!--<version>1.1</version>-->
<!--</dependency>-->
<!--</dependencies>-->
</project>
I am using a multi-module project.
Right-click on pom.xml and then click on "Add as Maven Project".
Right click the module and select the Make Module "project module name" option from the pop up menu. The messages will be shown. But go to Problems and see now. This will clear and correct this problem.
In my case the problem ocurred after uprgrading IJ from 14.x to 15.x and disappeared when I issued Build -> Rebuild Project
In case of IntelliJ , Right click on the POM.xml file of your project and click on the option "Add as Maven Project".
My problem with this error under 2019.3.4 is related to the build delegating to Maven. Idea is letting Maven build my project first and that build is failing because I broke a test. I get around this problem by not allowing IDEA to delegate to Maven. On Mac OS Catalina: Intellij -> Preferences -> Build, Execution, Deployment -> Build Tools -> Runner and uncheck Delegate IDE Build/run actions to Maven
The messages originates from Line 43 in /org/jetbrains/jps/maven/compiler/MavenResourcesBuilder.java, so my guess is that it is no pom.xml issue but rather IntelliJ Idea related.
If you dig further into the code, it looks for a file called maven/configuration.xml and from what I see, it searches in some temporary directory.
Maybe you should try and start your build as clean as possible.
Quick solution (IntelliJ IDEA):
Right-click on the project, the select Maven->Reimport
In my case, I had to use the following trick:
Right click the module name in the project panel
Select "Open Module Settings"
In the pop-up window, click Dependencies
Select java version 1.8.0_151
I have the same error after a Intellij Idea version upgrade (2016.3 to 2017.1):
Error:Maven Resources Compiler: Maven project configuration required
for module 'MODULE_NAKE' isn't available. Compilation of Maven
projects is supported only if external build is started from an IDE.
But my solution was another. Somehow, I think the Intellij lost the maven version used in my project. I was using maven 2.2.1 but Intellij was trying to use maven 3.x.
So, my solution was adjust this configuration in:
File > Settings > Build, Execution, Deployment > Build Tools > Maven
And set the maven version to 2.2.1.
I had this problem after an Intellij Idea version upgrade. The fix was to wait for it to finish indexing. Then I think it downloaded some stuff it needed.
Makes me think that the other answers on this thread about the IJ version upgrade probably just needed to wait as well - by the time they finished trying a few things the problem was fixed by itself.
In my case this was caused by a misconfiguration of IntelliJ. A long time ago I had been experimenting with the Lifecycle options within the Maven Projects view and had left a few phases in a sub module checked as Execute Before Build.
Because I had completely forgotten having checked these, it took me quite some time to understand the connection with the error messages in the Problems view. After unchecking the Execute Before Build switches of the affected phases everything went back to normal and particularly running unit tests became much faster.
In my case, I invalidated the cache and restarted the IDE. It worked, not sure why though.
I chose the bundled maven installation which helped me.
It could also be something to do with using a symlink to reference the maven installation..
it turns out the version of intelliJ I use (2018.3) can't import maven projects using apache-maven-3.6.2
modify .idea/compiler.xml,add config(should change module name to yourself):
In my case I got this error message, because my Maven configuration in IntelliJ was broken. I had entered invalid options into VM options for importer at Preferences:Build,Execution,Deployment->Build Tools->Maven->Importing.
After deleting these options IntelliJ started to behave normal again.
I am using IDEA with WSL2 and Windows10.
My problem occurred when IDEA automatically set the JDK in WSL2 as project JDK.
After Setting my JDK back to Windows JDK, the error disappearred.
In my case I had all configured to execute the hot reload with devtools after each file change namely:
File -> Settings -> Build, Execution, Deployment -> Compiler -> Enable "Build project automatically";
File -> Settings -> Advanced Settings -> Allow auto-make to start even if developed application is currently running.
The maven related error in the Auto-build tab was being displayed and only went away when I deleted .idea folder in the root directory, opened the project again, built the project without maven config (build as Ant project), and configured all again.
After the reset the error disappeared and the maven build was executed without errors.
I was troubled by this problem all afternoon,the solution in stackoverflow is not usefull for me.But I just solved this problem by accident,i don't kown how it worked,but it is effective.If you have the same project structure.
project structure
you can try this
try this button
and you will found all children project is build success. then you can run all project normally.
Go to event log and from there you will see options, what need to fix it

What correct maven dependencies to specify for JBehave tutorial project?

I want to study the java spring portion of the Jbehave-tutorial project at https://github.com/jbehave/jbehave-tutorial.
The README.MD states the REQUIREMENTS for building at the bottom:
Building the tutorial has been tested with Maven 3.0.5-3.2.1 and JDK 1.6-1.7. Newer versions of Maven and JDK should work but could also present issues.If you find any, please report them via JIRA
On my computer My Computer I am running Maven Version: 3.3.3 and STS Version: 3.6.4 for 64-bit Windows 7.
I really don't want to make an Atlassian account in order to resolve this issue if I can resolve it on StackOverflow.
So these are the steps I took to build JBehave-tutorial on my machine:
git clone https://github.com/jbehave/jbehave-tutorial.git
mvn clean install -Pstable # Issued in the main parent folder 'jbehave-tutorial'
Imported into Spring Tool Suite (STS) as an existing maven project.
Received the following errors in STS:
This lead me to believe that maven did not correctly download and build those dependencies so I looked into the .m2\repository\org\jbehave folder and this is what I seen.
Did anybody else get this to work?
What workarounds are there?
What correct maven dependencies to specify for JBehave tutorial project in pom.xml(s)?
I'm not immediately clear on your specific situation but here are dependencies required to use JBehave without Spring. (example pom below - you'll only need gherkin if your user scenarios are in gherkin).
https://stackoverflow.com/questions/30685909/jbehave-dependencies-not-available-in-central-maven-repo
I'm also going to hazard a guess that you're going to need the below at the appropriate version.
<dependency>
<groupId>org.jbehave</groupId>
<artifactId>jbehave-spring</artifactId>
<version>4.0.3</version>
</dependency>
Maven cannot find "SNAPSHOT" dependencies.
You need to google "Maven + dependency name without specified version" and check what is the latest version of them and make appropriate changes in pom file.
For example I have jbehave-web-runner version 3.6-beta-2 NOT 3.6-SNAPSHOT.

Maven war contains extra dependencies if not built standalone

I've got a war which I'm trying to reduce the dependencies contained in it's WEB-INF/lib as they're provided by the ear and if they're only in the ear it resolves some classloader issues I've had.
If I run mvn clean install in the module for the war it builds in only the dependencies I want. If I go up a level and run mvn install on the project (the war's defined as a module in the pom.xml at this level) then the war is repackaged with a lot more dependencies.
Why would the behaviour be different and how can I stop all these extra dependencies getting in?
I've tried following the advice here but saw no difference in the behaviour: http://maven.apache.org/plugins/maven-war-plugin/examples/skinny-wars.html
Maven 2.0.6, maven-ear-plugin 2.4.1, maven-war-plugin 2.1-beta-1 (I can't change the versions, I'm on a closed network). Thanks in advance.
ETA: A mvn clean install at the project level gives me the results I want. An mvn clean and then an mvn install adds in the extra jars that I don't want.
Run mvn dependency:tree to see where the (probably transitive) dependencies are coming in from.
You'll want to read "Maven the Definitive Guide" (free PDF by Sonatype) in order to get an in depth understanding of how Maven deals with Dependency management.
And please do find a way to upgrade to maven 2.1.0 (preferably 2.2.1), and the latest versions of the plugins, earlier versions are notoriously buggy.

Categories