What exactly happens when you hit the IntelliJ "run" button? [duplicate] - gradle

IntelliJ IDEA 2016.3 add the ability to delegate build/run to Gradle.
It's clear that when the delegate option is on Gradle is doing everything.
My question is what exactly IntelliJ is doing when this option is off?
I'm asking this because I have custom code inside my Gradle files and it does not seems like this code is executed when building in IntelliJ. When I run gradlew build everything works just fine.

IntelliJ has its own build system, called JPS, which uses the IntelliJ IDEA project and .iml files as the project model. When you're using IntelliJ IDEA's default build system to build the project, it does not execute any code in Maven or Gradle files; it uses its own logic, which can only be extended by writing plugins to JPS.

Related

Maven Build Scripts Found - IntelliJ - What are the build scripts, where are they cached?

So basically, as the title of the post states, I'm wondering what IntelliJ is referring to when it says that Maven build scripts were found? Are these scripts that Maven keeps cached or are they IntelliJ specific? If they are generated by Maven, where are they stored/ how can I view them if that is possible?
Thanks!
This notification is to inform you that you are working with IntelliJ IDEA project that is not linked to the external build system (Maven or Gradle).
When you open a project in IntelliJ IDEA that was not initially imported from Maven/Gradle and IDE detects pom.xml or build.gradle files in the project, it will display a notification so that you can properly import the project from the build script.
Build script in your specific case is a pom.xml file stored inside a project directory. It's recommended that you open Maven projects by importing the root pom.xml file.
When a project is not imported from the external build system, your source roots configuration may be incomplete and you may be missing the dependencies.

Intellij Idea fails to sync with Gradle: JvmOptions error

I'm trying to open freshly created Gradle project in Intellij Idea 2020.1. However, when trying to sync with Gradle, either on startup or manually, Idea shows the following text in "build" window:
'void org.gradle.process.internal.JvmOptions.<init>(org.gradle.api.internal.file.FileCollectionFactory)''void org.gradle.process.internal.JvmOptions.<init>(org.gradle.api.internal.file.FileCollectionFactory)'
and the project is not being imported.
I'm not able to find any references to this error. Could you give me some hints on how to troubleshoot this problem?
This turned out to be the issue with incorrect updating.
As I found, the Gradle plugin in my Intellij Idea installation contained two copies of Gradle libraries, for two different version of Gradle. In the fresh installation of Intellij Idea, there is only the Gradle 6.1. By removing the old version of Gradle from the plugin, problem was resolved.

Can I run IntelliJ unit tests in a maven project without re-running maven goals?

I have a project with a deep maven structure and am evaluating switching from Eclipse to IntelliJ.
I've imported the top-level pom.xml. I know that I can:
Build the whole project with maven goals (I use 'test-compile' to build the test classes)
Run the tests from the IntelliJ test runner. This seems to find the classes/test-classes from the target folder of the project.
However, I would like to just change a test or the code under test, save it, and rerun it without having to manually run the maven test-compile again (like I could with Eclipse). Is this possible with IntelliJ?
I think the issue is that the IntelliJ 'Build Project' action does not build the test classes (and other classes) into the target folder that the test runner looks in.
If you import a Maven project in IntelliJ IDEA, you will be able to build and run the tests from the IDE instead of Maven which is a lot faster because of the incremental compilation.
Make sure this option is disabled and use JUnit Run/Debug configuration, don't run the maven goals.
Thanks to the suggestion from #CrazyCoder, I was able to get this working by following these steps, as I think the issue was Eclipse artifacts fighting with IntelliJ artifacts:
Remove all .classpath, .project and .iml files from the entire code tree
Remove .idea from the root - we need to start again
Open the top-level pom.xml in IntelliJ
If needed, perform a mvn compile (needed for me due to some generated sources)
Rebuild your project
After this, don't open your project in Eclipse again!

How to have Buildship recognize existing projects in Eclipse Mars

I just converted my Maven project to a gradle project. It was a multi project structure:
master-project
pom.xml
---->project1
-------->pom.xml
---->project2
-------->pom.xml
---->project3
-------->pom.xml
I ran a gradle init on it and have this structure now:
master-project
build.gradle
---->project1
-------->build.gradle
---->project2
-------->build.gradle
---->project3
-------->build.gradle
Everything builds fine, and I have been able to get some things done with that I couldn't figure out how to do with Maven, so that's great. Next step was to integrate that into the IDE since the Maven Dependencies are gone since I have removed the pom.xml files.
However the project isn't recognized as a gradle project - and I am not sure how to change that?
In Eclipse Mars it's still recognized as a Maven build, not gradle....
Thanks in advance.
EDIT: I reimported the projects which enabled the plugin for Eclipse. Now I am having weird behavior.
The build works from the command line, however when attempting the same execution from within Eclipse, it fails trying to copy the file dependencies.
For example:
Couldn't copy dependency jakarta-regexp-1.4.jar
java.nio.file.NoSuchFileException: C:\Users\user.m2\repository\jakarta-regexp\jakarta-regexp\1.4\jakarta-regexp-1.4.jar -> build\jfx\app\lib\jakarta-regexp-1.4.jar
I haven't changed the repo from maven yet - just changed the build scripts. This is running from the master project. So I am confused as to why the script would work from the commandline but not from within eclipse.
EDIT 2: Turns out this behavior is also present when running from the command line when the --daemon flag is set. Is there anyway to run the tasks without the daemon in Buildship? Or perhaps a way to fix this issue when the --daemon flag is enabled?
Thanks.
The issue with the build was that there is a leak in the JDK when bundling the JRE with the native app. This only happens when running with the --daemon flag (which all IDEs user). Therefore until this is fixed you will need to run gradle --stop and then run the clean.
The plug in I am using is no longer running the native task when running with --daemon.

IntelliJ steps through the wrong lines when debugging remote Java application

I tried to remote debug a maven plugin for a liquibase project with Intellij. IDEA is highlighting the wrong source code line.
I manually built and installed the plugin in my local maven repository from sources in my Intellij project. Intellij version is 11.1.3 and maven version is 3.0.4 running on Ubuntu 12.04.
For debugging the maven plugin I used mvnDebug comand.
If someone has any ideas please give me some advice. I'm not too used to remote debugging (in fact this is the second time I've done this).
For me, whenever IntelliJ is highlighting the wrong line, it was always because the version of the JAR/classes being used to run the application differs from my source files - i.e. different version of the sources were used to build the JAR and/or classes.
You are going to have to be sure that you are working from the exact source that was used to build the classes you are debugging.
You can verify this by looking at the classpath being used to launch the application, locating the JAR file or classes directory that contains the classes you are debugging, and verifying that they were built from the sources you are inspecting.
Note that when you are debugging third-party libraries, you often can download the "sources" jar (see IntelliJ2-IDEA get Maven-2 to download source and documentation).
If you stumbled across this post, and sure that the source and JAR are the same code, then this could be your problem.
http://youtrack.jetbrains.com/issue/IDEA-8021
Instead of doing remote debugging you can run the plugin directly from IntelliJ.
Have the liquibase plugin project loaded in IntelliJ by just pointing at the pom.xml.
Choose Edit Configurations...
Press the + button to Add New Configuration.
Select Maven.
Enter the Working directory to the project you want to run the plugin on.
Enter the Command line. Could be process-sources, compile or liquibase:status depending on what you want to do.
Press OK
Set a breakpoint in the Liquibase Mojo.
Now you can start this configuration by pressing Shift+F9.
Maven will start and finally you will see that your plugin is waiting at the breakpoint!
Make sure that you have defined the plugin in the target pom.xml with correct version and also that you build the plugin before launching it. You can ensure that by enabling Make in the Before Launch pane.

Resources