I am unable to import the dependencies as shown in the screenshots. What am i doing wrong here. Please help thank you.
Above your <dependencies> section, add the following:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
And then right click on your project -> Maven -> Reimport. This will reconfigure the compiler for language level (instead of default 1.5 which is much too low), and more importantly import the libraries in your dependencies.
try
right click the project
1.configure-->convert to maven project
2.Maven--->update maven project-->force update of snapshots and releases
Related
In NetBeans 7.2, I'm having trouble finding how to compile using -Xlint:unchecked in a Maven project. Under an Ant project, you can change compiler flags by going to Project Properties -> Compiling, but Maven projects don't seem to have any such option.
Is there any way to configure the IDE to compile with such flags using Maven?
I guess you can set compiler arguments in your pom.xml. Please refer this http://maven.apache.org/plugins/maven-compiler-plugin/examples/pass-compiler-arguments.html
<compilerArgument>-Xlint:unchecked</compilerArgument>
I want to elaborate on #Nishant's answer. The compilerArgument tag needs to go inside plugin/configuration tag. Here is a full example:
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<testSource>1.8</testSource>
<testTarget>1.8</testTarget>
<compilerArgument>-Xlint:unchecked</compilerArgument>
</configuration>
</plugin>
</plugins>
This works for me...
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>11</source>
<target>11</target>
<compilerArguments>
<endorseddirs>${endorsed.dir}</endorseddirs>
</compilerArguments>
<compilerArgs>
<arg>-Xlint:unchecked</arg> <-------this right here ---->
</compilerArgs>
</configuration>
</plugin>
</plugins>
The pom file information is spot on. I had the additional challenge of building someone else's Maven project in Jenkins and not having access to the pom file repository.
I created a pre-build step to insert the compiler parameter into the pom file after downloading it from git, for example
sed -i 's|/target> *$|/target>\n<compilerArgument>\n-Xlint:deprecation\n</compilerArgument>|' $WORKSPACE/pom.xml
Everytime I modify the dependencies inside the pom.xml file in my IntelliJ Maven project, the Java version is set to 1.5 and I have to receonfigure my project.
The following settings are modified by Maven:
Settings | Compiler | Java Compiler -> Target bytecode version
And Project Settings | Modules -> Language Level
Why is this happening and what do I have to do, so that maven doesn't vandalise my settings?
You have to explicitely set the java version in your pom file so that version 1.5 doesn't get set by default.
<project>
[...]
<build>
[...]
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
[...]
</build>
[...]
</project>
Specify the java version under properties.
<properties>
<java-version>1.8</java-version>
</properties>
and to use the same version with maven compile or package then include the same version in compile plug-in
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
I have a mid-size project in java eclipse, in which all dependencies were being manually imported into the build path. For the sake of sanity, I wanted to convert it to a maven project.
The problem is: I had the source level/jre defined for 1.8 and when i converted to a maven project, It switched to the default of 1.5.
I tried some answers around SO for forcing the source compliance in maven to 1.8 but it didn't work.
I added to the
<build>
<plugins>
<plugin>
<groupId>[project group id]</groupId>
<artifactId>[project artifact id]</artifactId>
<version>0.0.1-SNAPSHOT</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
Is anything missing here?
EDIT1: Forget me, I'm bad. The correct version is:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
after this you need these two
preference - > java - > compiler - > 1.8 and language level to 8
preference - > java -> installed JRE -> JDK 1.8
The default compliance level for Maven is 1.5 and every time that I update a maven project in Eclipse it sets back the compliance level from 1.6 to 1.5 which is really annoying for me.
I know that I can set the target to 1.6 in the POM file but the problem is that I cannot set this in the parent POM and expect the children to inherit it. So I have to do it for every single Maven module. How can I set it in my Maven project or in the whole eclipse once for a "lifetime" without modifying every single Maven module!?
I know that I can set the target to 1.6 in pom file but the problem is that I cannot set this in the parent pom and expect the children to inherit it.
Setting the <source> and <target> version in the parent pom does work.
For example, in my parent pom, I have:
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
</plugins>
</pluginManagement>
If you are having problems, you might want to check that:
the child specifies the correct version of the parent;
the parent pom specifies both source and target values;
you have run mvn install on the parent; and
mvn help:effective-pom on the child project shows the expected source/target values.
After modifying the poms, you may need to select both projects and use Maven->Update Project.
Another way (if you do not have already compiler plugin defined) is to set just these properties in your pom file:
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
Details: https://maven.apache.org/plugins/maven-compiler-plugin/examples/set-compiler-source-and-target.html
This worked for me..
<build>
<finalName>ProjectName</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.1</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>
</build>
Go to the project's pom.xml and insert below in between tags. Then the eclipse plugin (like m2eclipse) should rebuild the workspace.
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
</plugins>
</build>
Note: this is project-level as only the project's pom.xml is affected.
In NetBeans 7.2, I'm having trouble finding how to compile using -Xlint:unchecked in a Maven project. Under an Ant project, you can change compiler flags by going to Project Properties -> Compiling, but Maven projects don't seem to have any such option.
Is there any way to configure the IDE to compile with such flags using Maven?
I guess you can set compiler arguments in your pom.xml. Please refer this http://maven.apache.org/plugins/maven-compiler-plugin/examples/pass-compiler-arguments.html
<compilerArgument>-Xlint:unchecked</compilerArgument>
I want to elaborate on #Nishant's answer. The compilerArgument tag needs to go inside plugin/configuration tag. Here is a full example:
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<testSource>1.8</testSource>
<testTarget>1.8</testTarget>
<compilerArgument>-Xlint:unchecked</compilerArgument>
</configuration>
</plugin>
</plugins>
This works for me...
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>11</source>
<target>11</target>
<compilerArguments>
<endorseddirs>${endorsed.dir}</endorseddirs>
</compilerArguments>
<compilerArgs>
<arg>-Xlint:unchecked</arg> <-------this right here ---->
</compilerArgs>
</configuration>
</plugin>
</plugins>
The pom file information is spot on. I had the additional challenge of building someone else's Maven project in Jenkins and not having access to the pom file repository.
I created a pre-build step to insert the compiler parameter into the pom file after downloading it from git, for example
sed -i 's|/target> *$|/target>\n<compilerArgument>\n-Xlint:deprecation\n</compilerArgument>|' $WORKSPACE/pom.xml