I know this question is not new. But it seems that there is no definite answer. This answer from 2012 states that if generated sources are placed under target/generated-sources/<tool> they will be compiled. ANTLR 4 maven plugin follows this paradigm. Per documentation, the default value of outputDirectory is: ${project.build.directory}/generated-sources/antlr4.
Now in my case I have a custom tool that generates sources. I've set its output directory to be at ${project.build.directory}/generated-sources/whatever and it didn't work. Regarding the whateverpart, I've tried to use the id of the goal that generates the sources and even tried to hijack antlr4 name. No result though.
When I try this solution that suggests using mojo build-helper-maven-plugin it compiles as expected. But according to maven guide to generating sources it should be working without any helper plugin, shouldn't it? Am I missing something?
Here is the POM (fragment) configuration that I use to generate the sources.
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.4.0</version>
<executions>
<execution>
<id>generate-code</id>
<phase>generate-sources</phase>
<goals>
<goal>java</goal>
</goals>
</execution>
</executions>
<configuration>
<includeProjectDependencies>false</includeProjectDependencies>
<includePluginDependencies>true</includePluginDependencies>
<executableDependency>
<groupId>com.company.product</groupId>
<artifactId>CodeGenerator</artifactId>
</executableDependency>
<arguments>
<argument>${basedir}/</argument>
<argument>${project.build.directory}/generated-sources/generate-code/</argument>
</arguments>
<mainClass>com.company.codegeneration.CodeGenerator</mainClass>
</configuration>
<dependencies>
<dependency>
<groupId>com.company.product</groupId>
<artifactId>CodeGenerator</artifactId>
<version>1.0-SNAPSHOT</version>
<type>jar</type>
</dependency>
</dependencies>
</plugin>
Your understanding is just a bit incorrect.
Nothing automatic, plugins generating source code typically handle that by adding their output directory (something like target/generated-sources/ by convention) as source directory to the POM so that it will be included later during the compile phase.
Some less well implemented plugins don't do that for you and you have
to add the directory yourself, for example using the Build Helper
Maven Plugin.
As the other answer noted, most plugins typically add the generated code as new source path.
Ex: See antlr4's Antlr4Mojo.java class. Here, the plugin is adding the generated classes to project source by calling addSourceRoot method in execute method.
// Omitted some code
void addSourceRoot(File outputDir) {
if (generateTestSources) {
project.addTestCompileSourceRoot(outputDir.getPath());
}
else {
project.addCompileSourceRoot(outputDir.getPath());
}
}
// Omitted some code
#Override
public void execute() throws MojoExecutionException, MojoFailureException {
// Omitted code
if(project!=null)
{
// Tell Maven that there are some new source files underneath the output
// directory.
addSourceRoot(this.getOutputDirectory());
}
}
// Omitted some code
So, you can either do this in your custom plugin or use the build-helper-maven-plugin.
After fiddling around for way too long till I got proper debuging setup in Netbeans 8.2 with Spring Boot 1.4.3 I figured I write down my findings as Q&A for others.
The problem is that the default configuration for Netbeans fails to properly launch Spring in debug mode and when you search the internet you only find the outdated information in the Spring docs that won't work.
The solution is simple if you know how. Please find the correct setup instructions below.
Tested and works with Netbeans 8.2 and Spring-Boot 1.4.3:
First of all make sure you have the Spring Maven plugin included (this should be already included when making a new Netbeans Spring project):
<plugins>
...
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
...
</plugins>
Also it is a good idea to include the Spring Devtools like this:
<dependencies>
...
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
</dependency>
...
</dependencies>
Now navigate to your project settings -> Actions -> Debug project and set the following:
Execute goals:
spring-boot:run
Set properties:
run.jvmArguments=-Xdebug -Xrunjdwp:transport=dt_socket,server=n,address=${jpda.address}
jpda.listen=true
Now run your application via the usual debug button and Spring should properly connect to the JVM debugger.
Spring Boot 2.x
To enable Netbeans debugging for a Spring Boot 2.x project (and more specifically version 2.x of the spring-boot-maven-plugin) the procedure is exactly the same, except the run.jvmArguments property name has changed to spring-boot.run.jvmArguments:
spring-boot.run.jvmArguments=-Xdebug -Xrunjdwp:transport=dt_socket,server=n,address=${jpda.address}
jpda.listen=true
Testing NetBeans 8.2 and Spring Boot 2.0.1, I was not able to make things work following #TwoThe's instructions. First, I encountered an issue where all I saw was "JPDA Listening Start..." in the output window. To resolve that problem, I added Spring Devtools as an optional dependency. Second, even though debugging appeared to be running okay, the "Debugging" window, which normally displays the list of active threads, was empty and breakpoints that I set were not triggered. Third, attempting to stop the debugging session by pressing the red "Finish Debugger Session" button would not stop the Tomcat server.
Instead of changing the execute goals to "spring-boot:run", I found that it was sufficient to use the default "Debug project" action execute goals:
process-classes org.codehaus.mojo:exec-maven-plugin:1.2.1:exec
.. and properties:
exec.args=-Xdebug -Xrunjdwp:transport=dt_socket,server=n,address=${jpda.address} -classpath %classpath ${packageClassName}
exec.executable=java
jpda.listen=true
(As a sidenote, debugging as a regular Java application is apparently the recommended approach to debugging Spring Boot applications in Eclipse; see How to debug Spring Boot application with Eclipse?)
One helpful tip is that if you want to debug using a certain Spring Boot profile, say "debug", you can prepend "-Dspring.profiles.active=debug " to the "exec.args" property. See also: Spring boot running a fully executable JAR and specify -D properties
Tested on NetBeans9
Action: Add any name
Set Properties: select Add> button, select Debug Maven Build
And debug as always -> IDE debug button
If you are still having the problem after applying all above mentioned fixes, remove all your breakpoints and try again.
Window -> Debugging -> Breakpoints -> Delete All Breakpoints
POW
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
</dependency>
buld
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
Debug Project
Excute Goals : package
Set Properties:netbeans.deploy.debugmode=true netbeans.deploy=true
Change
Excute Goals : spring-boot:run
Set Properties: spring-boot.run.jvmArguments=-Xdebug -Xrunjdwp:transport=dt_socket,server=n,address=${jpda.address}
jpda.listen=true
and Netbeans Press debug project -- not navigator--> spring-boo-run ... What was the difference? spring-boot.run.jvmArguments:
Using IntelliJ IDE can't compile any projects. Screenshots of settings below:
Used JDK:
Project SDK and Language level:
Language Level:
Anybody have any ideas?
Go to File > Settings > Build, Execution, Deployment > Compiler > Java Compiler If on a Mac, it's under Intellij IDEA > Preferences... > Build, Execution, Deployment > Java Compiler
Change Target bytecode version to 1.8 of the module that you are working for.
If you are using Maven
Add the compiler plugin to pom.xml under the top-level project node:
<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>
(Hoisted from the comments.)
Note: If you don't mind reimporting your project, then the only thing you really need to do is change the pom and reimport the project, then IntelliJ will pick up the correct settings and you don't have to manually change them.
You need to go to Settings and set under the Java compiler the following:
also check the Project Settings
This looks like the kind of error that Maven generates when you don't have the compiler plugin configured correctly. Here's an example of a Java 8 compiler config.
<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">
<!-- ... -->
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
<!-- ... -->
</project>
The quickest way I found:
press:CTRL + SHIFT + A (For Mac ⌘ + SHIFT + A)
type: java compiler
press: ENTER
In the Settings window, set the Target bytecode to 1.8
(or 9 for java9)
There are two ways to solve this problem:
Set settings (File -> Settings -> Build, Execution, Deployment -> Java Compiler):
Add a build section to your pom.xml:
Many answers regarding Maven are right but you don't have to configure the plugin directly.
Like described on the wiki page of the Apache Maven Compiler Plugin you can just set the 2 properties used by the plugin.
<project>
[...]
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
[...]
</project>
I fixed this by going to Project Structure -> Modules, find the module in question, click on Dependencies tab, change Module SDK to Project SDK.
I fixed it just by changing target compile version to 1.8. Its in:
File >> Settings >> Build, Execution, Deployment >> Compiler >> Java Compiler
You need to go to the /.idea/compiler.xml and change target to required jdk level.
In my case I fixed this issue by opening .iml file of project (it is located in project root folder and have name same as the name of project) and changing line <orderEntry type="jdk" jdkName="1.7" jdkType="JavaSDK" /> to <orderEntry type="jdk" jdkName="1.8" jdkType="JavaSDK" />
I had everything configured as in others answers here but by some reason Idea updated .iml file incorrectly.
I fixed it by modify my POM file. Notice the last comment under the highest voted answer.
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
The source must matches the target.
I just re-import maven button, then the error disappeared.
In your Gradle app level file >> compileOptions add this two lines
android {
compileOptions {
...
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
...
}
}
If you are working with Android-studio 1.3, Follow the below steps -
Go to File - Project Structure
Under modules- app-Properties tab, choose
Source Compatibility -1.8 and
Target Compatibility - 1.8.
And you are good to go.
Under compiler.xml file you will find :
<bytecodeTargetLevel>
<module name="your_project_name_main" target="1.8" />
<module name="your_project_name_test" target="1.8" />
</bytecodeTargetLevel>
and you can change the target value from your old to the new for me i needed to change it from 1.5 to 1.8
With Intellij, using Maven, you must check that Intellij has auto-imported your project.
You can check by clicking on the Maven tab on the right of your Editor.
If your Project is not here, then add the pom.xml file by clicking on +.
Obviously, the project must also have the relevant <build/> :
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
I've just spent a while struggling with the same problem.
The only thing that worked for me was not using the built mvn (3.3.9) but pointing it to an external downloaded version (3.5.0). Finally the project opened and everything was good.
Don't forget to set dependencies for your module:
This issue occurs if your module is configured with Annotation processor and other module is not.Set the same configuration for all the modules as it wold be cyclic dependency.
the below code working fine by my side. I just add it in the pom.xml file.
<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>
For me, the problem was about Maven not able to find proper configurations, since these items were specified in parent pom.
Changing File -> Settings -> Build, Excecution, Deployment -> Maven -> User Settings file to point to my custom settings with proper repositories fixed the problem that was otherwise hiding.
Found out about the problem through Help -> Show log in explorer -> clicking the log file, when previously only got the error in the title and "java.lang.NullPointerException" in the console.
If none of the other answers work, check your Module SDK.
I had this error pop up for me after I had updated the project SDK to 1.8, the Javac compiler to 1.8, etc. The setting that was the problem for me was the "Module SDK".
(on Linux) Go to File > Project Structure... then in the window that opens, select Modules under Project Settings. Select the module in question from the list and then the Dependencies tab and make sure that Module SDK is set appropriately.
I have checked all of the above but the error still occurs.
But reimport all maven Projects (reload button inside Maven Projects panel) works in my case.
The only thing that helped me was to delete .idea/compiler.xml file.
Solution of the problem is very simple.You have to open .idea/compiler.xml file on your İdea Project and
You should write appropriate target version
I've been toying around with the latest changes in the gwt-maven-plugin. Most notably, the new packagings gwt-app and gwt-lib.
To my understanding, if I have some code that I'd like to reuse between different GWT apps, gwt-lib packages all needed sources and *.gwt.xml files in the jar right next to all classes. It works like a charm.
If I opt for a multi-module maven reactor build, everything is detected on compile time and I'm able to build and deploy successfully without any hassle. If I try to develop however, the shiny GWT 2.7 SuperDevMode is unable to detect changes in the gwt-lib projects, obviously because they are referenced from the jars and not the actual sources directory where they were changed.
To illustrate, I used the modular-requestfactory archetype by Thomas Broyer.
mvn archetype:generate \
-DarchetypeCatalog=https://oss.sonatype.org/content/repositories/snapshots/ \
-DarchetypeGroupId=net.ltgt.gwt.archetypes \
-DarchetypeArtifactId=modular-requestfactorcom.testy \
-DarchetypeVersion=1.0-SNAPSHOT
and I entered the following information:
Define value for property 'artifactId': : mvngwt
Define value for property 'version': 1.0-SNAPSHOT: :
Define value for property 'package': com.test: :
Define value for property 'module': App: : MvngwtApp
Define value for property 'module-short-name': mvngwtapp: :
Afterwards I created an additional maven module called "mvn-gwt-client-api", which contains a single class that is to be used by the mvn-gwt-client. The end structure looks like this:
mvngwt/
--mvngwt-client/
--mvngwt-client-api/
--mvngwt-server/
--mvngwt-shared/
--pom.xml
The goal is to be able to edit the files in mvngwt-client-api (e. g. the only class currently: MvngwtApi.java), then recompile in SuperDevMode and actually see the changes immediately without restarting the CodeServer.
A working copy of the project can be found here: https://github.com/elnicko/maven-gwt-test
PS: I tried to work it out with the build-helper-maven-plugin:
<profiles>
<profile>
<!-- elnicko: add to support CodeServer hot compile for referenced libraries -->
<id>env-dev</id>
<activation>
<property>
<name>env</name>
<value>dev</value>
</property>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<executions>
<execution>
<id>add-shared-sources-to-classpath</id>
<!--
<phase>process-classes</phase>
<phase>compile</phase>
-->
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>${basedir}/../mvngwt-client-api/src/main/java</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
However it didn't improve the situation.
Any hints/pointers/ideas greatly appreciated.
Edit:
I am able to use the SuperDevMode incremental compilation by using the aforementioned build-helper-maven-plugin configuration, changing the mvngwt-client-api packaging from "gwt-lib" to "jar", and adding a "maven-source-plugin". That way maven compilation and deployment work the same way, but the CodeServer is made aware of the changes in the source directory of mvngwt-client-api. Nevertheless, the question remains open, how one can use the new "gwt-lib" without losing the CodeServer incremental compilation. The diff may be seen here: https://github.com/elnicko/maven-gwt-test/compare/master...working_wihtout_gwt-lib_but_with_jar_packaging
You have to use <type>gwt-lib</type> in your dependency.
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>mvngwt-client-api</artifactId>
<version>${project.version}</version>
<type>gwt-lib</type>
</dependency>
Actually, if you run Maven with -X you'll see in the logs:
[DEBUG] Adding sources for com.test:mvngwt-client:gwt-app:1.0-SNAPSHOT
[DEBUG] Ignoring com.test:mvngwt-shared:jar:1.0-SNAPSHOT; neither a java-source, gwt-lib or jar:sources.
[DEBUG] Adding sources for com.test:mvngwt-shared:jar:1.0-SNAPSHOT
[DEBUG] Ignoring com.test:mvngwt-client-api:jar:1.0-SNAPSHOT; neither a java-source, gwt-lib or jar:sources.
[DEBUG] Ignoring com.google.gwt:gwt-user:jar:2.7.0; neither a java-source, gwt-lib or jar:sources.
[DEBUG] Ignoring com.google.gwt:gwt-dev:jar:2.7.0; neither a java-source, gwt-lib or jar:sources.
[DEBUG] Ignoring com.google.gwt:gwt-codeserver:jar:2.7.0; neither a java-source, gwt-lib or jar:sources.
Maybe those should be emitted at INFO level rather than DEBUG…
BTW, instead of the build-helper-maven-plugin, you could have just used a <type>java-source</type> or <classifier>sources</classifier> dependency, like it's done for the mvngwt-shared module.
I need to use Java 6 but NetBeans is not using it even after all the configurations I made. It keeps running Maven with the Default that is Java 8 for my IDE. The same configuration runs well on Eclipse so I don't get what I am doing wrong.
I don't want to define the compiler in the nb-configuration.xml since I would have to commit the file. I would expect NetBeans to get it right from the POM.
General information:
I am using NetBeans 8.0.1 (fully updated) running on Java 8
NetBeans 8 needs JDK 7+ in order to work
Using Maven 3.2.3, but the embedded (Maven 3.0.5 didn't work as well)
All Maven plugins are up to date
To reproduce simply create a Maven project of any type in NetBeans. In my case I tried with Java, Web and EJB but none worked.
The following image shows that the JDK is properly added to the IDE.
Tools > Java Platforms
JDK 1.6 is added.
POM configurations that I have tried:
Properties
<properties>
<maven.compiler.source>1.6</maven.compiler.source>
<maven.compiler.target>1.6</maven.compiler.target>
</properties>
Compiler Plugin
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
Enforcer Plugin
Enforcing Java 6 gives the following error:
Detected JDK Version: 1.8.0-25 is not in the allowed range [1.6,1.7).
------------------------------------------------------------------------
BUILD FAILURE
Configuration for the enforcer:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>1.3.1</version>
<executions>
<execution>
<id>enforce-versions</id>
<goals>
<goal>enforce</goal>
</goals>
<configuration>
<rules>
<requireJavaVersion>
<version>[1.6,1.7)</version>
</requireJavaVersion>
</rules>
</configuration>
</execution>
</executions>
</plugin>
Test code for Java 6
The following code should not compile:
import java.nio.file.Files;
import java.time.LocalTime;
public class JavaVersionChecker {
public static void main(String[] args) {
System.out.println(Files.class); // Java 7 API
System.out.println("Time: " + LocalTime.now()); // Java 8 API
// Print Java version
System.out.println(System.getProperty("java.version"));
}
}
Test Output
The test code compile with Java 7 and 8 API, but only Java 6 should be accepted.
------------------------------------------------------------------------
Building java6_project 1.0-SNAPSHOT
------------------------------------------------------------------------
--- exec-maven-plugin:1.2.1:exec (default-cli) # java6_project ---
class java.nio.file.Files
Time: 19:24:05.997
1.8.0_25
------------------------------------------------------------------------
BUILD SUCCESS
------------------------------------------------------------------------
Total time: 0.610 s
Finished at: 2014-11-21T19:24:06-02:00
Final Memory: 6M/123M
------------------------------------------------------------------------
JDK 6 should be detected by the IDE
As suggested by the comments I made the configuration work using a hint property, which is also very well documented in the generated nb-configuration.xml.
Configuration added to the pom.xml:
<properties>
<netbeans.hint.jdkPlatform>JDK_1.6</netbeans.hint.jdkPlatform>
</properties>
As I understand the compile version for NetBeans needs to be set by a proprietary parameter, which is very simple to set up.
Useful nb-configuration.xml details:
Properties that influence various parts of the IDE, especially code
formatting and the like. You can copy and paste the single
properties, into the pom.xml file and the IDE will pick them up. That
way multiple projects can share the same settings (useful for
formatting rules for example). Any value defined here will override
the pom.xml file value but is only applicable to the current project.
This error was caused by an old entry in nb-configuration.xml
Just adding this property to pom.xml as suggested by #BonanzaOne did not worked for me.
By changing
<netbeans.hint.jdkPlatform>JDK_1.6.0_34</netbeans.hint.jdkPlatform>
to
<netbeans.hint.jdkPlatform>JDK_1.6</netbeans.hint.jdkPlatform>
directly in nb-configuration.xml, Netbeans picks the existing JDK 1.6 automaticaly.