Groovy file does not compile in Intellij IDEA - maven

I have maven project wit java and groovy tests.
In command line maven compilation all tests are running, but in my IDEA project (which is created automatically, by "AutoImport maven projects", IDEA copies groovy files to /target/test-classes without compiling them.
My gmaven plugin looks like
<plugin>
<groupId>org.codehaus.gmaven</groupId>
<artifactId>gmaven-plugin</artifactId>
<version>1.3</version>
<executions>
<execution>
<goals>
<goal>generateStubs</goal>
<goal>compile</goal>
<goal>generateTestStubs</goal>
<goal>testCompile</goal>
</goals>
<configuration>
<providerSelection>1.7</providerSelection>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-all</artifactId>
<version>${groovy.version}</version>
</dependency>
</dependencies>
</plugin>

I had the same issue and had to change in Idea the following setting:
Settings->Compiler->Resource patterns
It was !?*.java
I changed it into
!?.java;!?.form;!?.class;!?.groovy;!?.scala;!?.flex;!?.kt;!?.clj
It would be better to be able to specify it into the pom file though but haven't found a way yet.

GMaven plugin is only intended for maven compilation. Idea uses the Groovy compiler included in groovy-all jar. For Idea to get a hold of that add a project dependency, e.g.:
...
<groupId>yourproject</groupId>
<artifactId>yourproject</artifactId>
<version>1.0.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-all</artifactId>
<version>${groovy.version}</version>
</dependency>
</dependencies>
...

Solved by removing and creating from scratch IDEA project (ipr file)

Please change folder type of groovy files as Source Root. Step for same is Right Click on folder -> Select option - 'Make Directory as' -> Source Root

As suggested above
I changed it into
!?.java;!?.form;!?.class;!?.groovy;!?.scala;!?.flex;!?.kt;!?.clj
This setting was already available in my intellij.
Still the code was not generating Fixed it by Setting->Compiler
and check compile independent module in parallel and after that it got generated

This is similar to #Opal's answer, but is relevant for tests, as asked in the question:
In the IDE go to Files->Project Structure->Project Settings->Modules. In the Project files tree select the src->test->groovy directory. Hit Alt+T to make the groovy directory the test source root

Please check Settings | Compiler | Resource patterns. It appears that *.groovy somehow suits there and therefore it's copied into output instead of being compiled.

You have to change folder type of groovy files to make directory as source Root.

Related

Maven exec:java run executable plugin dependency jar results in NPE

I'm making a maven application that uses a sparql endpoint service. I'd like to have a maven goal to download the sparql endpoint and start the service but it seems that maven have some problems to configure the classpath.
I'm using blazegraph and its artifact at https://mvnrepository.com/artifact/com.blazegraph/bigdata-jar.
Here it is my plug-in configuration in pom.xml:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.6.0</version>
<executions>
<execution>
<goals>
<goal>java</goal>
</goals>
</execution>
</executions>
<configuration>
<mainClass>com.bigdata.rdf.sail.webapp.StandaloneNanoSparqlServer</mainClass>
<includePluginDependencies>true</includePluginDependencies>
<includeProjectDependencies>false</includeProjectDependencies>
<executableDependency>
<groupId>com.blazegraph</groupId>
<artifactId>blazegraph-jar</artifactId>
</executableDependency>
<addOutputToClasspath>false</addOutputToClasspath>
</configuration>
<dependencies>
<!-- https://mvnrepository.com/artifact/com.blazegraph/blazegraph-jar -->
<dependency>
<groupId>com.blazegraph</groupId>
<artifactId>blazegraph-jar</artifactId>
<version>2.1.4</version>
<scope>runtime</scope>
<type>jar</type>
</dependency>
</dependencies>
</plugin>
The debug output hints that the plug-in can't find the artifact:
Caused by: java.lang.NullPointerException
at org.codehaus.mojo.exec.AbstractExecMojo.findExecutableArtifact(AbstractExecMojo.java:278)
at org.codehaus.mojo.exec.ExecJavaMojo.determineRelevantPluginDependencies(ExecJavaMojo.java:650)
at org.codehaus.mojo.exec.ExecJavaMojo.addRelevantPluginDependenciesToClasspath(ExecJavaMojo.java:568)
at org.codehaus.mojo.exec.ExecJavaMojo.getClassLoader(ExecJavaMojo.java:520)
at org.codehaus.mojo.exec.ExecJavaMojo.execute(ExecJavaMojo.java:301)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:134)
... 27 more
What am I missing?
Edit 1
This question is not a duplicate of What is a NullPointerException, and how do I fix it? because the exception is thrown by Maven since it can't find the right artifact in the list of dependencies (but it should).
Edit 2
Thanks to #Sean Patrick Floyd I've partially solved the issue. There are still some problem in the classpath configuration, I guess. Now Maven finds the main class and the jar but after the execution I get an other NPE in compiled code. Looking in the open source code of blazegraph it seems that it can't open a resource inside the executable jar.
Here is the line that causes NPE:
System.setProperty("jetty.home",
jettyXml.getClass().getResource("/war").toExternalForm());
https://github.com/blazegraph/database/blob/master/bigdata-jar/src/main/java/com/bigdata/rdf/sail/webapp/StandaloneNanoSparqlServer.java#L142
The <executableDependency> mechanism is used for binaries, not for JARs, see the usage page. Remove that part, these settings should be sufficient:
<mainClass>com.bigdata.rdf.sail.webapp.StandaloneNanoSparqlServer</mainClass>
<includePluginDependencies>true</includePluginDependencies>
just wanted to post this here as it fixed my issue and nothing else did, downgrade the version to 1.5.0 worked for me on exec:java for the same plugin configs posted in the question, inspired by the issue https://github.com/mojohaus/exec-maven-plugin/issues/76

Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12:test (default-test) on project.

I have been trying from a couple of days to resolve the following error but I am unable to resolve it :(
My module's pom.xml file is:
<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>
<artifactId>junitcategorizer</artifactId>
<groupId>com.topdesk.test.junitcategorizer</groupId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>..</relativePath>
</parent>
<artifactId>junitcategorizer.instrument</artifactId>
<name>JUnitCategorizer InstrumentationAgent</name>
<description>The agent used to instrument the called Java classes</description>
<dependencies>
<dependency>
<groupId>org.ow2.asm</groupId>
<artifactId>asm-commons</artifactId>
<version>4.0</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.10</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
</manifest>
<manifestEntries>
<Premain-Class>com.topdesk.junitcategorizer.instrument.InstrumentationAgent</Premain-Class>
<Agent-Class>com.topdesk.junitcategorizer.instrument.InstrumentationAgent</Agent-Class>
<Can-Redefine-Classes>true</Can-Redefine-Classes>
<Can-Retransform-Classes>true</Can-Retransform-Classes>
<Boot-Class-Path>${project.artifactId}-${project.version}.jar</Boot-Class-Path>
<Can-Set-Native-Method-Prefix>true</Can-Set-Native-Method-Prefix>
</manifestEntries>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>1.5</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<artifactSet>
<includes>
<include>org.ow2.asm:*</include>
</includes>
</artifactSet>
<relocations>
<relocation>
<pattern>org.objectweb.asm</pattern>
<shadedPattern>org.shaded.asm</shadedPattern>
</relocation>
</relocations>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
I am getting the following error:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.
12:test (default-test) on project junitcategorizer.instrument: There are test failures.
[ERROR]
[ERROR] Please refer to D:\Masters\thesis related papers and tools\junitcategorizer\junitcategorizer.instrument\target\surefire-reports for the individual test results.
[ERROR] -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12:test (default-test) on project junitcategorizer.instrument: There are test failures.
Please refer to D:\Masters\thesis related papers and tools\junitcategorizer\junitcategorizer.instrument\target\surefire-reports for the individual test results.
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:212)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:116)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:80)
at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:120)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:347)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:154)
at org.apache.maven.cli.MavenCli.execute(MavenCli.java:582)
at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:214)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:158)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
Caused by: org.apache.maven.plugin.MojoFailureException: There are test failures.
Please refer to D:\Masters\thesis related papers and tools\junitcategorizer\junitcategorizer.instrument\target\surefire-reports for the individual test results.
at org.apache.maven.plugin.surefire.SurefireHelper.reportExecution(SurefireHelper.java:83)
at org.apache.maven.plugin.surefire.SurefirePlugin.writeSummary(SurefirePlugin.java:673)
at org.apache.maven.plugin.surefire.SurefirePlugin.handleSummary(SurefirePlugin.java:647)
at org.apache.maven.plugin.surefire.AbstractSurefireMojo.executeAfterPreconditionsChecked(AbstractSurefireMojo.java:137)
at org.apache.maven.plugin.surefire.AbstractSurefireMojo.execute(AbstractSurefireMojo.java:98)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:132)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:208)
... 19 more
[ERROR]
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
I tried the following but did not help:
mvn dependency::tree
mvn clean install -U or Right-click on "project" Go to "Maven" >> "Update"
Please help me!
This solved my issue.
It was 2.10 in my POM, just updated to 2.19.1 and refresh the POM
Add to your pom :
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19.1</version>
</plugin>
</plugins>
In your error code he didn't find surefire plugin so add it
This is what solves the problem:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19.1</version>
<configuration>
<testFailureIgnore>true</testFailureIgnore>
</configuration>
</plugin>
from Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.10:test
This happens when Maven tries to run your test cases while building the jar. You can simply skip running the test cases by adding -DskipTests at the end of your maven command.
Ex: mvn clean install -DskipTests
or
mvn clean package -DskipTests
Was facing the same issue multiple times and I have 2 solutions:
Solution 1:
Add surefire plugin reference to pom.xml. Watch that you have all nodes!
In my IDEs auto import version was missing!!!
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M3</version>
</plugin>
</plugins>
Solution 2: My IDE added wrong import to the start of the file.
IDE added
import org.junit.Test;
I had to replace it with
import org.junit.jupiter.api.Test;
Try this it works!
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M3</version>
<configuration>
<testFailureIgnore>true</testFailureIgnore>
<shutdown>kill</shutdown> <!-- Use it if required-->
</configuration>
</plugin>
It worked for me with version 3.0.0-M1.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M1</version>
</plugin>
You might need to run it with sudo.
This is a kind of test failure.#SpringBootApplication annotation contains these configurations.
1) #Configuration
2) #ComponentScan
3) #EnableAutoConfiguration
#EnableAutoConfiguration is the reason for this error. This will try to automatically configure application according to dependencies in your pom.xml
As a example when you have spring-data-jpa dependency in pom it will try to add configuration to application by looking at application.properties file for data source. So you need add data source to solve that.
For MySQL :
spring.jpa.hibernate.ddl-auto=create
spring.datasource.url=jdbc:mysql://localhost/lahiru
spring.datasource.username=root
spring.datasource.password=
Or
You could hide this by skipping testing.
mvn install -DskipTests
For more details.
I get exactly the same stacktrace when tests fail.
More to the top you should see messages identfying the failing test classes.
Or go to
D:\Masters\thesis related papers and tools\junitcategorizer\junitcategorizer.instrument\target\surefire-reports
and have a look at the failure reports.
Fix the problems and your build is ok.
Good news : Your poms seem to be ok, Maven can compile and execute tests.
Here is the simplest way to resolve this error:
1) Go to your pom.xml file path
2) And edit the pom.xml like:
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.12</version>
</plugin>
</plugins>
3) Save the file
That's it.
I have the same problem and try almost all these suggestions and another options but nothing works for my case.
So I had run verbose command: (mvn install -X) and saw the problem with Jacoco lib, and finally found this answer that works for me.
Change the Jacoco lib version in my pom file.
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.4</version>
If you skip tests by command or Intellij maven tool it will work, but its not solution. As solution simply add following plugin.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.0</version>
</plugin>
Check your test files. You must clear all test files error on your project and try Clean and build.
If you are using ubantu then try to run MVN with sudo.
I got same error for
mvn -Dtest=PerfLatency#latencyTest test -X
But
sudo mvn -Dtest=PerfLatency#latencyTest test -X
Solved my problem
Make sure the name of the class created in the package is something like somethingTest.java
Maven only picks the java files ending with Test notation.
I was getting the same error and resolving the names of all my classes by adding 'Test' at the end made it work.
I was facing the same problem and how i resolved see below steps or Image:
Clicked on Windows menu item of eclipse
Clicked on preferences
select Installed JREs
Add your installed jdk's path(JRE home: C:\Program Files\Java\jdk1.8.0_201\jre`)
Add JRE name: jdk1.8.0_201
Clicked on Finish
Apply changes and close
enter image description here
Change the version number to 2.19.1 works for me :)
`<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19.1</version>
<configuration>
<systemPropertyVariables>
<xmlOutputDir>${project.build.directory}/surefire</xmlOutputDir>
</systemPropertyVariables>
</configuration>
</plugin>`
after a few days of wondering, my solution was that I forgot to use #Test annotation before the #BeforeEach
My situation might be a bit different - but I was using Java 11 instead of Java 8.
I was facing the same kind of issue, your version numbers in the dependency of Selenium, TestNG, Junit should the same that you have used in your project. For example, in your project you are using the Selenium version 3.8. This version number should be mentioned in the dependency.
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>7.0.0-beta1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.8.1</version>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.8</version>
<scope>test</scope>
</dependency>
</dependencies>
3 years already, but the same thing happened to me and I wanted to contribute with my case. Using the #nikk solution I got better results, but other errors still appeared, although yes, I was allowed to package.
However, my task was to implement the code of a co-worker on the server and it did not happen to him in his test environment, so I decided to investigate a little more since the code was functional and did not correspond to me touching anything .
In the end it turned out that his application inserted mysql tables into a database that did not exist. The solution was as easy as creating such a database and the error disappeared.
This issue could be related to the already busy port. Surefire run on 5005 port. So you need to make sure that this port is free. If not change it or kill the process. This happens in Intellij some time.
This error is brought up for many different reasons so everyone has a different solution. However, your own webapp should hold the answer for it.
You can look it up in
/module_with_failure/target/surefire-reports/*.txt
It may be better to set the surefire-plugin version in the parent pom, otherwise including it as a dependency will override any configuration (includes file patterns etc) that may be inherited, e.g. from Spring Boots spring-boot-starter-test pom using pluginManagement
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.0</version>
</plugin>
</plugins>
</pluginManagement>
</build>
I just adjust the cucumber version, because I had a JUnit dependency in a low version compared with the other version of cucumber in my pom file.
<!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-java -->
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-java</artifactId>
<version>6.9.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-picocontainer -->
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-picocontainer</artifactId>
<version>6.9.0</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-junit -->
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-junit</artifactId>
<version>6.9.0</version>
<scope>test</scope>
</dependency>
I have faced the same problem and try all the method mentioned above. Then I identified that the problem is in the pom file.
so if you have given
TestNG.xml
in your pom file. Then, Perhaps the location of the TestNG.xml file is not correct.
By writing above command it will search the file in the root directory. If your TestNG.xml file is present somewhere else other then root directory then give that path or else copy the whole path of the TestNG.xml file from the server and paste it.
In my case I have done like below:
/home/ubuntu/TestNG.xml
and the problem resolved.
Karate is case sensitive so making sure your file and folder name and also package reference in Test runner file.
After trying for some time I was able to fix the issue so thought of posting as it can be helpful to someone in the future:
It has nothing to do with your pom.xml file and does not require any additional library or plugins.
You are getting the path of the file where failing reports are present. Something like this:
[ERROR] Please refer to /Users/{username}/{folderPath}/{projectName}/target/surefire-reports for the individual test results.
Click on that path and go to the folder. Within the folder search for the file testing-failed.xml file and open it in any of the editors.
You will be able to see the Class/Test which is failing. Something like this:
<class name="PackageName.ClassName">
Go to that file in your IDE and try to run it. If it's failing then fix it and try to run the mvn clean install again.
This should fix the issue, at least for me it worked.
I had a similar error yesterday:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.21.0:test (default-test) on project my-working-tests: There are test failures.
The error was solved by implementing the following two steps:
adding the 2.22.1 to the pom.xml fie.
run command mvn -o test
In the step step, the errored test got past, but my terminal threw error, Could not resolve dependencies, for the next test. That made sense because the command, mvn -o test, was doing the test offline, without downloading dependencies. Please note that if you do not have a next test, you will not meet the same new error as I met.
Then, I rerun the command mvn install again. It ran successfully.
Please check the code for the step 1
Old code (raised the error):
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
.......
</configuration>
</plugin>
Updated code (solved the error):
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.1</version>
<configuration>
.......
</configuration>
</plugin>
Hope it helps to your error.
If you're hitting this issue in Eclipse, you can try right click the project > Run as > Maven Install
For any missing plugin, add it to your pom.xml file under the plugins section and Run Maven Install again. I hope it helps.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M7</version>
</plugin>
HI All can you try adding the below in your POM and then use
mvn clean compile and then mvn install.
<!-- https://mvnrepository.com/artifact/junit/junit -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>

maven/apt generated classes in eclipse

Using following configuration in master pom, some classes (metamodel FYI) are generated for all child projects having jpa entities under target/generated-sources, as expected.
<plugin>
<groupId>org.bsc.maven</groupId>
<artifactId>maven-processor-plugin</artifactId>
<version>2.2.4</version>
<dependencies>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-jpamodelgen</artifactId>
<version>4.3.10.Final</version>
</dependency>
</dependencies>
<executions>
<execution>
<id>process</id>
<goals>
<goal>process</goal>
</goals>
<phase>generate-sources</phase>
<configuration>
<processors>
<processor>org.hibernate.jpamodelgen.JPAMetaModelEntityProcessor</processor>
</processors>
</configuration>
</execution>
</executions>
</plugin>
This works perfectly from Maven and Netbeans.
Some team members still use Eclipse. There, generated classes aren't found automatically. They can be opened if added manually to the "build path" (whatever it means as this is redundant to pom.xml). However, that's not stable and will be reset whenever they "update the project" (shouldn't even be needed but...) to reflect project's maven configuration.
My question is, how to configure Eclipse to use this project's configuration automatically? I don't want to change the project's pom.xml too much, as they are perfectly legal and work well outside of Eclipse, which I just want to be taught to behave correctly.
UPDATE: M2Eclipse is installed and doesn't solve this, which is basically our problem.
There ist a project/Eclipse-Plugin called M2Eclipse (link).
The plugin includes the following feature:
Dependency management for Eclipse build path based on Maven's pom.xml

Add external library .jar to Spring boot .jar internal /lib

I have an external .jar that cannot be imported from public repositories using pom.xml, it's sqljdbc41.jar.
I can run the project locally from my IDE, and everything will work. I referenced the library after downloading it like so:
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>sqljdbc41</artifactId>
<version>4.1</version>
<scope>system</scope>
<systemPath>${basedir}/lib/sqljdbc41.jar</systemPath>
</dependency>
When I run mvn clean package to create my .jar file and try to run the created .jar, a mistake will pop up, which mentions the SQL Server references are not valid. I then extracted my .jar file and true enough, everything that is referenced in the pom.xml file properly gets downloaded and added, however, my SQL Server does not.
I can, in a very hacky way* just manually add the sqljdbc41.jar to my /lib folder after it's been compiled as a .jar, and it'll work, however that seems highly unoptimal. What would be a better approach?
*Opening the .jar file with Winrar, going to the /lib folder, manually selecting my sqljdbc41.jar file, then make sure to select the No Compression option bottom left where Winrar gives you compression options, in case you find this by Google and no one answered.
you can set 'includeSystemScope' to true.
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<includeSystemScope>true</includeSystemScope>
</configuration>
</plugin>
You could install the sqljdbc41.jar in your local repository :
mvn install:install-file -Dfile=path/to/sqljdbc41.jar -DgroupId=com.microsoft.sqlserver -DartifactId=sqljdbc41 -Dversion=4.1 -Dpackaging=jar
And then declare the dependency as a standard dependency :
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>sqljdbc41</artifactId>
<version>4.1</version>
</dependency>
If you use a remote artifact repository (nexus, archiva...) you also need to deploy the artifact on this repository. You can find more here : https://maven.apache.org/guides/mini/guide-3rd-party-jars-remote.html
Another way, you can put it into the resources folder, such as resources/lib/xxx.jar, then config the pom.xml like this:
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>sqljdbc41</artifactId>
<version>4.1</version>
<scope>system</scope>
<systemPath>${basedir}/src/main/resources/lib/sqljdbc41.jar</systemPath>
</dependency>
In Spring Boot: I also faced similar issue and below code helped me.
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>1.5.7.RELEASE</version>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
<configuration>
<includeSystemScope>true</includeSystemScope>
</configuration>
</plugin>
</plugins>
</build>
It works for me:
project {root folder}/libs/ojdbc-11.2.0.3.jar
pom.xml:
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc</artifactId>
<version>11.2.0.3</version>
<scope>system</scope>
<systemPath>${basedir}/libs/ojdbc-11.2.0.3.jar</systemPath>
</dependency>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<includeSystemScope>true</includeSystemScope>
</configuration>
</plugin>
In my case, the fault was providing a version number without "dot" in tag:
<dependency>
<groupId>jdk.tools</groupId>
<artifactId>jdk.tools</artifactId>
<scope>system</scope>
<version>1</version>
<systemPath>${basedir}/src/main/resources/lib/tools.jar</systemPath>
</dependency>
This one works:
<dependency>
<groupId>jdk.tools</groupId>
<artifactId>jdk.tools</artifactId>
<scope>system</scope>
<version>1.8</version>
<systemPath>${basedir}/src/main/resources/lib/tools.jar</systemPath>
</dependency>
When Spring-Boot projects are used with maven or gradle plugins they packaged the applicaiton by default as executable jars.
These executable jars cannot be used as dependency in any another Spring-Boot project because the executable jar add classes in BOOT-INF/classes folder. This means that they cannot be found when the executable jar is used as a dependency because the dependency jar will also have the same class path structure as shown below.
If we want to use project-A as a maven dependency in project-B then we must have two artifacts. To produce the two artifacts, one that can be used as a dependency and one that is executable, a classifier must be specified. This classifier is applied to the name of the executable archive, leaving the default archive for use as a dependency.
To configure a classifier of exec in Maven, you can use the following configuration:
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<classifier>exec</classifier>
</configuration>
</plugin>
</plugins>
</build>
So the MAJIC WORD here is <classifier>exec</classifier> this will create a jar structure as below and then it could easily be conusmed by spring-boot project as maven dependency jar on class path.
The above plugin need to be add in project-A pom that is going to be used as dependency in project-B. Same is explained in spring documentation section 16.5. as well.
In order to work through the local repository, the target .jar file that we will work with must be in the s2 folder. Several methods can be used for this:
The file can be taken manually and put in the relevant place (not
preferred). The same process can be done by installing it via the
console.
Relevant Remote URL is written in the .pom file dependencies and
automatically places it in the s2 folder when Intellij is refreshed
(validate) in the IDE used.
The same process can be done by addressing the .pom file dependencies via the centeral repository.
Attention: ComponentScan should not be forgotten for the related jar work on SpringBot.

IntelliJ + Groovy + Spock: no Groovy library is defined for module

I have been trying to create a Groovy project with Spock testing in IntelliJ IDEA.
Here are steps that I followed:
Created Groovy project and added Maven support.
Added Spock dependencies and plugin. I am using POM very similar to this one:
https://github.com/mariuszs/java-spock-test-sample/blob/master/pom.xml
Due to conflicting Groovy dependency I removed Groovy 2.2 library from the Module Settings->Libraries. This allowed me to run tests.
I created a Groovy class in "src/main".. but I get the error when I try to run it:
Groovyc: Cannot compile Groovy files: no Groovy library is defined for module...
I am probably missing something because I am tired of trying different configurations for half of the day.
For fully groovy project try GMavenPlus
Sample project: https://github.com/mariuszs/groovy-maven-sample
Install GMavenPlus IntelliJ Plugin.
IntelliJ dont recognize source directories src/main/groovy, configure this manually as shown below from Project Settings -> Modules window:.
Configuration
<project>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.gmavenplus</groupId>
<artifactId>gmavenplus-plugin</artifactId>
<version>1.5</version>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-all</artifactId>
<version>2.4.4</version>
</dependency>
<dependency>
<groupId>org.spockframework</groupId>
<artifactId>spock-core</artifactId>
<version>1.0-groovy-2.4</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
There were two steps to fixing the (broken) project:
Update the groovy-all dependency to version 2.2.1, which I had installed on my machine.
In "projectName.iml" file replace
orderEntry type="library" exported="" scope="TEST" name="Maven:
org.codehaus.groovy:groovy-all:2.2.1" level="project"
with this one:
<orderEntry type="library" name="groovy-2.2.1" level="application" />
This situation was caused by two factors: me being new to the IDE and the fact that things kinda-sorta work even when you mis-configure the project. I still think this Q&A might be useful to someone in the future.
I had this "Cannot compile Groovy files: no Groovy library is defined for module" issue recently. I needed to mark my groovy test directory as a 'Test Sources Root' in IntelliJ.
Right click on dir --> Mark Directory as --> Test Sources Root
For me the solution was to open a .groovy file in the specific folder/module and then idea gave a little popup showing the the Groovy SDK is not configured. Then I clicked on configure -> OK and voila.

Resources