IntelliJ is clearing helpful log info on debug error - java

IntelliJ is deleting helpful println and error messages on Debug mode error.
It clears the Debug console and leaves me with:
Execution failed for task ':AutoAuth.main()'.
> Process 'command '/Applications/IntelliJ IDEA CE.app/Contents/jbr/Contents/Home/bin/java'' finished with non-zero exit value 1

While the root case of the problem is not clear as the Minimal, Complete, and Verifiable example was not provided, there are several things that can be done to workaround this issue:
See if it runs from the command line Gradle. If it does run, the issue is probably with the JDK or with the way IDE is generating the Gradle script to start it. If it fails, the issue is probably system specific or some wrong Java VM options are used.
JetBrains Runtime bundled with IntelliJ IDEA is not designed for development. As described in the documentation, you should download and install your own JDK to compile and run the apps.
By default IntelliJ IDEA will build and run using Gradle, but this can be changed back to IntelliJ IDEA build/run configurations:

Related

What tasks do I need in order to be able to run my Gradle-based Java project from IntelliJ IDEA?

I have a large mostly-Java multi-project Gradle build that I have opened in IntelliJ IDEA. This was imported correctly (as far as I can tell). One of the projects inside this is an old-school Java Swing GUI application.
When I attempt to run its main class from within IntelliJ using the "Run Main.main()" context menu, IntelliJ launches a Gradle task ":folder:project:Main.main()", which fails because of course there is no task in this project's build.gradle called "Main.main()".
The exact error looks like:
Execution failed for task ':folder:project:Main.main()'.
> A problem occurred starting process 'command 'C:/path/to/ojdk8/bin/java.exe''
What exactly am I expected to put into my build.gradle to get this to work?
As a secondary question, is it possible to make such a task agnostic over the actual main()-method containing class? This project contains several such classes that expose different functionality.
For context, I am a long-time Eclipse user evaluating IntelliJ for my organization. This is on IntelliJ IDEA 2022.1, Gradle 5.6.4, OpenJDK 1.8.0_275
I feel like I am missing something completely obvious, but I could not find the answer with any web searching or reading the IntelliJ documentation.
My mental model of what was happening was wrong. No specific Gradle tasks are required.
It turns out the root cause was Windows. When re-running the task with --stacktrace option I was able to see the actual error, which turned out to be:
CreateProcess error=206: The filename or extension is too long
Googling with this info I found this previous Stackoverflow question. Its answered got me onto the "Shorten command line" flag in the Run/Debug configuration. Setting this to "JAR manifest" solved the problem.

Intellij IDEA debugger not working on Gradle Vert.X project

I'm developing a project using Vert.X framework using Gradle build tool. The problem I have is that breakpoints in IntelliJ simply doesn't work in any way I've tried.
Here is a run configuration for Vert.X which I use in Gradle:
run {
args = [
'run', mainVerticleName,
"-conf", confPath,
"--redeploy=$project.ext.watchForChange",
"--launcher-class=$mainClassName",
"--on-redeploy=$project.ext.doOnChange"
]
}
So the deployment is done using Gradle, runs without any issues, IntelliJ debugger is connected, but breakpoints are not working.
The ways I've tried to make it work:
1) Gradle run configuration. Here is a run configuration for Intellij IDEA:
Tried to use a Remote debugging tool, started application with the following VM options:
-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=8000
But this didn't work.
2) Application configuration:
In this case I just can't start the project as I get the following message on the startup:
Error: Could not find or load main class io.vertx.core.Launcher
Vert.X Core library is in the classpath and configuration seems to be correct, so can't get were is the problem.
The source code of the project is public and can be found on GitHub:
vertx-gradle-architecture-starter
Vert.X version - 3.4.0. Gradle version - 3.4.1. IntelliJ IDEA version - 2016.3.5. OS - MacOS Sierra 10.12.3.
Interesting fact is when I deploy Vert.X from tests - breakpoints work. Any ideas why breakpoints doesn't work in cases I've described above?
Here are solutions to both issues. Thanks to #CrazyCoder for help on this.
1) run command is run in separate VM. So, to make it work, I've added --java-opts argument to the script:
run {
args = [
'run', mainVerticleName,
"-conf", confPath,
"--redeploy=$project.ext.watchForChange",
"--launcher-class=$mainClassName",
"--on-redeploy=$project.ext.doOnChange",
// used for attaching remote debugger
"--java-opts", "-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=8000"
]
}
This allows to attach Remote debug configuration on port 8000.
2) By default, Intellij IDEA creates separate modules per source sets, so I had source sets for api_main and api_test modules. After turning off this feature - Application debug run started to work.
This can be turned off in Gradle Settings. Preferences -> Build, Execution, Deployment -> Build Tools -> Gradle: uncheck create separate modules per source set.
This is an IntelliJ IDEA issue - reference.
I had the exact same issue and following worked for me. redeploy, launcher and on-redeploy options are not necessary in intelliJ. if we remove those the debug works after application is up.
run {
args = [
'run', mainVerticleName,
"-conf", confPath
]
}

Unit tests terminated in Debug mode

I'm using IntelliJ IDEA 15.0.2 (Community Edition) under Windows 7 and Windows 10 Pro, Gradle 2.9, JDK 1.7.0_65. Operating systems installed as guests under VMware Workstation 11.1.3
I have created Android Gradle application with single empty activity and wanted to check how unit test support works. There is a single unit test module ApplicationTest.java created by IDE, it contains only constructor. Right-clicking on [java] folder I created 'All in Module' JUnit3 test configuration.
Tests complete successfully when I Run them, however fail if I Debug the configuration. Failure reason says 'Terminated' (screenshot, IDEA log) which explained in the documentation as 'Test terminated. This status is assigned to tests that were cancelled by clicking the Stop button'. Just want to confirm that I didn't click the Stop button.
Logcat logs don't report any failures, IDE log reports 2 tests passed too. However problem remains as IntelliJ still reports a termination.
Sometimes I also getting 'Test framework quit unexpectedly' error and no tests succeed.
I've done some research and found similar questions, no real solutions mentioned. Have strong suspicion that this is a configuration issue.
What do I do wrong?
Gabor's suggestion seemed to fix this issue for me. On a Mac (and I presume on a Windows machine, but with a different route to get there) go to Preferences:
From the menu bar at the top Android Studio → Preferences
or
Hit ⌘ and , to jump straight to it.
Then in the menu search box type "instant". Uncheck the box that says "Enable instant run..", which looks like the image below.
That fixed it for me; didn't even need to restart/kill ADB.
It seems to be enabled by default, and I use it often to hot-swap changes during development, so I didn't think to turn it off when running Espresso tests.
In my situation, the problem is solved by setting in the test's run configuration:
Shorten command line -> JAR manifest.
To get rid of unit test problems in debug mode, I deleted all test folders in android studio explorer, then I commented three test implementation lines in build.gradle(module) file. Then I changed the combobox in android studio menu (top of the IDE) from "all in app" to "app".
https://i.stack.imgur.com/alPrS.png
In our case the fix (that may not be required in newer Android-versions) was to:
Open Edit Configuration... for All tests (or what ever you renamed it into).
Switch to Debugger tab.
And finally, in Debug mode combo-box, select the Java option, because:
Although we have lots of Native codes,
Android-studio 3.2.1 (which we were using) does not seem to support debugging both (but Java only mode works fine).

IntelliJ does not terminate Spring Boot applications build with gradle

I am using IntelliJ 13.1 on Linux and try to build a basic REST application following the example http://spring.io/guides/gs/spring-boot/
When I execute the target bootRun from within IntelliJ the intergrated tomcat server is started and everything works fine.
10:09:35: Executing external task 'bootRun'...
:compileJava UP-TO-DATE
:processResources UP-TO-DATE
:classes UP-TO-DATE
:findMainClass
:bootRun
But stopping the execution does not affect the gradle task:
10:11:40: External task execution finished 'bootRun'.
I still can access the tomcat instance on the configured port. Only closing IntelliJ will destroy the process.
I searched on this topic but could not find any reasonable answers. I wonder if it is a
gradle problem (using gradle wrapper version 1.11)
Linux problem (Ubuntu 12.04)
IntelliJ problem (IDEA 13.1.2)
Spring Boot problem (tried different versions from 1.0.0.RELEASE to 1.1.0.M2)
I am pretty sure it's an IntelliJ issue because:
When you run the bootRun from IntelliJ's Gradle integration and then press stop, the application continues to run as you mentioned.
However, if you use the command line and run gradle bootRun and then use Cntrl+C, the application stops just fine.
Note that my setup is Windows 7, IntelliJ 13.1.3, Gradle 1.12 and Spring Boot 1.1.0.M2.
If your need to is to be able to easily debug your application, all you need to do is run the Java (or Groovy) Class that has the main method, since that it is the easiest way to run Spring Boot applications! Kudos to Spring Boot for that!!!
Of course you can continue to use Gradle for tasks like running all the tests or creating the packaged application.
It's may not perfect solution. But for a quick fix, it will help you.
Goto terminal and apply this command to terminate the process
sudo kill -9 `sudo lsof -t -i:8080`
Note: Replace your port number instead of 8080
I know this answer was already answered, but as this is first topic when searching in Google, I thought in sharing an alternative I went with and didn't find in other topics I read.
My main problem with this terminate was that always I changed something in my classes, I needed to restart the server, and it would fail so I needed to stop/start the server sometimes.
To avoid this, I use spring-boot-devtools. Basically:
Applications that use spring-boot-devtools will automatically restart whenever files on the classpath change.
The only catch is that on Intellij it only makes the project if click Build > Make Project, so either set it to build automatically or remember to click on make.
To use, simply add the dependency to your build.gradle / pom.xml:
compile('org.springframework.boot:spring-boot-devtools')
I found this to be really useful in development.
I am using IntelliJ in Mac, running Spring boot application was giving the same issue. Whenever I run the app in Terminal and use CTRL + Z, the terminal will strop running the app. But when I run the app again in the same terminal, will give error saying the port 8080 was in use.
I just tried the option to close the Terminal session ( right click -> select -> Close Session). This will close the terminal, and when I clicked the terminal option again and ran the app, it ran smoothly.

how do you debug java annotation processors using intellij?

How do you debug java annotation processors using intellij?
Preferably using IDEA IntelliJ. I tried setting a breakpoint inside the processor and running but it did not break.
If you really need to debug an annotation processor, it might be better to run the annotation processor from the command line rather than within your IDE with debugging enabled and attach to that using your IDE's debugger.
If running javac directly, you can debug this by specifying the following extra parameters:
javac -J-Xdebug -J-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 ... (usual javac parameters go here)
If running Maven, use mvndebug instead of the standard mvn command - Maven runs the compiler in-process.
If running Ant, add the following to the ANT_OPTS environment variable before running:
-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000
With all these executions, the javac, Ant or Maven process will wait for you to attach your debugger before it actually starts executing. IntelliJ instructions for this are here. For Eclipse, here.
This tutorial is written for an Android project. Main module name is "app" as usual. The project contains a submodule called "annotation" which is subdependency of "app". "app" module runs annotation processing with gradle declaration
apt project(':annotation') .
SIMPLE VERSION
(run compilation from terminal and attach from IDE)
[REQUIRED] Add a new project configuration "+" -> "Remote". Check "Single instance only". All other settings are generated automatically. Leave <whole project> as the classpath. Port should be left as the default 5005.
[REQUIRED] Make sure you stop all gradle instances by calling: ./gradlew --stop
[REQUIRED] Run the command : ./gradlew --no-daemon -Dorg.gradle.debug=true :app:clean :app:compileDebugJavaWithJavac
Run the APT project configuration in debug mode as fast as possible :)
[HINT] We start with an EMPTY gradle.properties file
[HINT] DO NOT USE gradle daemon ( --no-daemon / org.gradle.daemon=false option )
[HINT] Run gradle in debug mode ( org.gradle.debug=true option )
[HINT] Run app's module compilation not the processor's module compilation (app's compilation runs annotation processing!)
We DO NOT normally add any Java compiler settings in Android Studio (i.e. File -> other settings -> Default settings)
EXTENDED VERSION (use gradle.properties)
Add the following to your gradle.properties file:
org.gradle.daemon=false
org.gradle.debug=true
Run the compilation from terminal:
./gradlew :app:clean :app:compileDebugJavaWithJavac
ADVANCED VERSION (just press debug in IDE)
Add a bash script to your project main dir (e.g. compile.sh)
#!/bin/bash
./gradlew :app:clean :app:compileDebugJavaWithJavac &
Remember about the '&' sign for background processing.
Go to APT configuration settings we created in step 1 and add a Before launch configuration. Select Run external tool.
Add the path to the compile.sh script we created earlier.
Warning
Messing up gradle compilation, NullPointer exceptions during compilation etc. sometimes result in AndroidStudio being stuck (frozen on gradle refresh stage). If you cannot stop gradle from the IDE then use this command in the terminal:
ps -A | grep gradle | awk '{ print $1; }' | xargs kill -9
Turning off debug option during project refresh sometimes helps Android Studio to come back to the right track.
Follow these steps, These worked for me on android studio for gradle project:-
1).In gradle.properties add following lines
org.gradle.daemon=true
org.gradle.jvmargs=-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005
2).Edit Build COnfiguration and add Remote Configration
3).Run recently created run configuration APT.
4).Add break point in annotation processing code and build overall project
It is possible to run javac and debug it, as indicated higher. However in my case it was tedious to write the complete classpath, so I wanted to leave this to IDEA. So in the module where I wanted to apply my annotation processor, just create a class with main method.
public static void main(String[] args) {
com.sun.tools.javac.Main.main("-proc:only",
"-processor", "my.pkgs.MyAnnotationProcessor",
"my/pkgs/any/ClassIWantProcess.java");
}
For this to work you need to add $JAVA_HOME/lib/tools.jar to your SDK's JARs (by default it is not there). This is the same reason why appservers compiling JSPs need this JAR on their classpath - they need the compiler.
Then just set proper working directory for your run configuration (so the relative path to the java file is correct), set your break-point into the processor and debug at your will!
Benefit - classpath is set already by IDEA and used by the "inner" javac, because here it is not a separate process. I believe it's possible to translate it to other IDEs too.
For a Maven project, this post, which explains the following steps in a little more detail, worked for me:
Add "Remote" run configuration and set "port" to 8000.
Issue the command mvnDebug clean install from the project's directory (on the command line).
Run the run configuration. In order to start a new session after the processes quit, repeat from (2).
Remember to run mvn install on the project's dependencies when they change (e.g. if the annotation processor is in a different artifact than the project you are debugging it from).
I found the following resource that can help you: http://code.google.com/p/acris/wiki/AnnotationProcessing_DebuggingEclipse
The guy explains step-by-step how to debug annotation processors using Eclipse.
Annotation processing occurs during compilation, so normal debugging won't work. If you want to debug it in the context of you project, you can use IntelliJ remote debugging, while having Gradle or Maven in debug mode. Then you can put breakpoints in the Annotation Processor's files.
See Debugging an Annotation Processor in any project.
Disclaimer: I wrote the post.
Debugging an annotation processor with IntelliJ IDEA and Gradle
Set a custom VM option -Dcompiler.process.debug.port=5005: press Ctrl + Shift + A and select Edit Custom VM Options... in the list of actions to add a custom VM option then restart the IDE.
Create a remote debug configuration with default parameters: Run -> Edit Configurations... -> Add New Configuration (Alt + Insert) -> Remote.
Set breakpoints.
Build with Gradle from the terminal: $ ./gradlew --no-daemon -Dorg.gradle.debug=true clean build (it's okay if the execution of the command is frozen, don't terminate a process).
Debug the remote debug configuration within the IDE (see step 3): select a suitable remote debug configuration and press Shift + F9.
Hope it helps somebody :)

Categories

Resources