Debug Gradle plugins with IntelliJ - debugging

Problem
I want to use the interactive debugger with IntelliJ. Unfortunately, I can't convince IntelliJ to load and compile the plugin. However, I can do gradle clean build and the plugin builds and runs its tests as expected.
Specifically, I'm trying to debug local changes to gradle-js-plugin and IntelliJ says it can't find com.google.javascript.jscomp.CompilerOptions as well as spock.lang.Specification. (I'm thinking maybe it's something about the way they are loaded, but that's a guess.)
Things I've tried
NOTE: I didn't revert any processes between steps.
0. My First Guess
I noticed a howto on docs.codehaus.org. IntelliJ couldn't find org.gradle.launcher.GradleMain, so I've adapted it to use GradleLauncher with the following:
import org.gradle.GradleLauncher
class GradleScriptRunner {
public static void main(String[] args) {
GradleLauncher.newInstance(
"-p",
"/path/to/gradle-js-plugin/src/test/resources/build.gradle",
"clean assemble"
)
}
}
Per GradleLauncher's documentation.
Outcome: IntelliJ won't compile the project.
1. Per Peter Niederwieser's answer Fix idea project & debug via plugin
Steps
~# cd /path/to/gradle-js-plugin && gradle cleanIdea idea
Opened the newly created project and attempted to debug using the ScriptRunner from step 0.
Outcome: Project compiles (yay!), but I can only hit breakpoints in GradleScriptRunner.groovy.
2. Per Peter Niederwieser's answer run gradle CLI w/ special options
1 & 2. Merged for clarity:
~# export GRADLE_OPTS="-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005"
~# gradle clean assemble
Listening for transport dt_socket at address: 5005
Configure IntelliJ to connect to this port and start debugging (see image):
For this step I tried the following .gradle file configurations:
1. Use only build.gradle
--build.gradle--
apply plugin: 'groovy'
apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'maven'
apply plugin: 'js'
buildscript {
repositories {
mavenLocal()
mavenCentral()
}
dependencies {
compile findProject "/path/to/gradle-js-plugin"
}
}
repositories {
mavenLocal()
mavenCentral()
}
Outcome:
FAILURE: Build failed with an exception.
* Where:
Build file '/path/to/gradle-js-plugin/src/test/resources/build.gradle' line: 13
* What went wrong:
A problem occurred evaluating root project 'resources'.
> No such property: findProject for class: org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
Total time: 8 mins 50.498 secs
2. Use both build.gradle and settings.gradle
--settings.gradle--
include "/path/to/gradle-js-plugin"
--build.gradle--
apply plugin: 'groovy'
apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'maven'
apply plugin: 'js'
buildscript {
repositories {
mavenLocal()
mavenCentral()
}
}
repositories {
mavenLocal()
mavenCentral()
}
Outcome:
FAILURE: Build failed with an exception.
* Where:
Build file '/path/to/gradle-js-plugin/src/test/resources/build.gradle' line: 5
* What went wrong:
A problem occurred evaluating root project 'resources'.
> Plugin with id 'js' not found.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
Total time: 13.553 secs
My Setup
Gradle
~# gradle -v
------------------------------------------------------------
Gradle 1.0
------------------------------------------------------------
Gradle build time: Tuesday, June 12, 2012 12:56:21 AM UTC
Groovy: 1.8.6
Ant: Apache Ant(TM) version 1.8.2 compiled on December 20 2010
Ivy: 2.2.0
JVM: 1.7.0_04 (Oracle Corporation 23.0-b21)
OS: Linux 3.2.0-2-amd64 amd64
Java
~# java -version
java version "1.7.0_04"
Java(TM) SE Runtime Environment (build 1.7.0_04-b20)
Java HotSpot(TM) 64-Bit Server VM (build 23.0-b21, mixed mode)
IntelliJ
IntelliJ IDEA Ultimate 117.499 w/ Bundled Gradle plugin
Hoping for
Any tips that'll get me into debug mode within the plugin.

I was able to debug gradle sources (including plugins) using -Dorg.gradle.debug=true (found on gradle forum):
Stop daemons if any:
./gradlew --stop
Run
./gradlew <task> --no-daemon -Dorg.gradle.debug=true
Connect remotely to gradle process (port 5005) - if using IntelliJ IDEA, see OP's image above
It should stop on breakpoints now.
BTW, I have created a separate IntelliJ IDEA project for gradle sources. Since I use gradle wrapper, I have grabbed the sources from
~/.gradle/wrapper/dists/gradle-1.11-all/7qd8qq8te5j4f5q9aaei3gh3lj/gradle-1.11/src
In IDEA I did File->Import Project, then selected the above path, then - "Create project from existing sources". Hit Next couple of times (made sure I didn't include any jars from lib/plugins directory, since IDEA would complain that most project files already exist).
I then created a remote debug configuration in that IDEA project and used it for debugging gradle.

First, it sounds like there is a problem with your IDEA Gradle project. If you run gradlew cleanIdea idea and then open the generated project from IDEA (rather than using the JetGradle plugin), all should be fine.
Second, if you still can't get the GradleMain/GradleLauncher (the former class does exist) approach to work, another approach is to debug the Gradle build as an external application. For that you need to add -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005 to the GRADLE_OPTS environment variable, run the build from the command line, wait until it suspends, and then start a "Remote" run configuration (with corresponding settings) from IDEA. At that point the debugger should connect to the Gradle process and you should be up and running.

IntelliJ IDEA 12.1 provides ability to debug gradle tasks out of the box - right-click target task at the JetGradle tool window tasks list and choose 'debug'

Related

Plugin [id: 'org.springframework.boot', version: '2.2.4.RELEASE'] was not found in any of the following sources:

I have just downloaded the springboot project from http://start.spring.io/. After running it I got this error.
* What went wrong:
Plugin [id: 'org.springframework.boot', version: '2.2.4.RELEASE'] was not found in any of the following sources:
- Gradle Core Plugins (plugin is not in 'org.gradle' namespace)
- Plugin Repositories (could not resolve plugin artifact 'org.springframework.boot:org.springframework.boot.gradle.plugin:2.2.4.RELEASE')
Searched in the following repositories:
Gradle Central Plugin Repository
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
Can any one please suggest what is root cause.
I would recommend you to run gradle build command in your terminal.
After this, do a gradle sync.
Must be some problem with your IDE.
Hope this solves your issue.
Accepted answer didn't work for me. I am able to resolve this after adding settings.gradle file in project root with,
settings.gradle:
pluginManagement {
repositories {
maven { url "<Repo_URL>" }
}
}
In my case I had configured a proxy from my job in the gradle.properties file, but I wasn't through their VPN.
If this is also your case, you can just comment the lines in that file, or just connect to the VPN if it is possible.
I could solve it as follows:
In the build.gradle file add the following lines:
Then you must open a command window and enter the folder where you have the project and execute the following order:
gradle build
That's it, with this your error must be solved ... Greetings !!!
None of the answers above worked for me, what fixed it was removing '.RELEASE' from the version (see here)
id("org.springframework.boot") version "2.5.4.RELEASE"
to
id("org.springframework.boot") version "2.5.4"
I had this problem, too. I used the OpenJDK 1.8 in my Spring Boot Project which for whatever reason created these complications, so I changed it to Amazon Corretto JDK 11 and the sync and build ran without errors.
If you use IntelliJ I would recommend you to change your SDK in the Project Structure/Project, Project Structure/Modules and Project Structure/SDKs and finally change the Gradle JVM to the new JDK version in Settings/Build, Execution, Deployment/Build Tools/Gradle/GradleJVM.
You are using incompatable gradle versions!!!
Check your gradle version:
your gradle version: gradle --version
project version: gradle/wrapper/gradle-wrapper.properties has property distributionUrl where you can find project version
If there is difference between your gradle version and project gradle version just download and use project gradle version https://gradle.org/releases/
I had this issue too, after trying out all the above it wasn't resolved. Then by trying gradle with other versions and other version of JDK, then I figured out that it was due to SSL authentication issue. In my case I have to add the security certificates from my local nexus repository to the JDK used by Gradle and the problem was resolved.
You can download the SSL certificates by browsing to the nexus repository manager and downloading it from the browser.
Guys for me was just old Gradle version, I updated following this link https://gradle.org/install/. For Ubuntu:
$ mkdir /opt/gradle
$ unzip -d /opt/gradle gradle-7.0.2-bin.zip
$ ls /opt/gradle/gradle-7.0.2
LICENSE NOTICE bin getting-started.html init.d lib media
Team adding below in build.gradle will help solve the issue:
allprojects {
apply plugin: 'maven'
apply plugin: "io.spring.dependency-management"
group = 'com.wnp'
version = '6.5.0-SNAPSHOT'
}
I had the same error. The reason was in my Windows machine path to the java certs in gradle.properties file having in correct format (i.e / instead of \ ) systemProp.javax.net.ssl.trustStore=<JAVA_HOME>\\lib\\security\\cacerts
The default build.gradle file generated by spring.io only includes mavenCentral in repositories. Not sure why, but once in a while, this error shows up. Add jcenter as well in there, it should work.
To be more clear repositories could look like following after change
repositories {
jcenter()
mavenCentral()
}
In my case I was on vpn and it blocked the traffic from above repositories.
First of all you need to understand the problem. Why did this error occur ?
The lines in build.gradle file
plugins {
id 'org.springframework.boot' version '2.2.4.RELEASE'
id 'io.spring.dependency-management' version '1.0.9.RELEASE'
id 'java'
}
tells gradle that "spring" and "java" are required for you project to build.
Plugins are task in gradle.
Now for compiling the project the gradle has to bring these plugins specified. for that it
will look in the repositories that you have specified. in
repositories {
mavenCentral()
}
So There must not be any problem with the Code. Refreshing must solve

How to run remote debug on local kotlinc

I want to compile some sample kotlin project using local compiler. I clone jetbrains/kotlin project from githib and build it. And now i have local compiler in /dist folder. How i need to configure gradle in sample project to use this local compiler in it and have an ability for remote debugging?
The simplest way is to build the whole toolchain and use it in your test projects.
To do that, run the install Gradle task in the Kotlin project:
./gradlew install
This will publish all of the project's Maven modules to the Maven local repository (~/.m2/repository by default) with the default snapshot version, which is 1.3-SNAPSHOT at the moment.
Then, in your test Gradle project:
If you apply the Gradle plugin using a buildscript block and an apply statement, add the mavenLocal() repository to buildscript { repositories { ... } } and use the snapshot version of the Gradle plugin:
buildscript {
repositories {
mavenLocal()
jcenter()
}
dependencies {
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.3-SNAPSHOT")
}
}
If the plugins are applied using the plugins { ... } block, modify the settings.gradle script and add the following:
pluginManagement {
repositories {
mavenLocal()
gradlePluginPortal()
}
}
and again, use the 1.3-SNAPSHOT version of the Gradle plugin:
plugins {
id("org.jetbrains.kotlin.jvm").version("1.3-SNAPSHOT")
}
In order to be able to debug the compiler, you need to run its process with a debugging agent waiting for a connection. Normally, the compiler is run in a daemon process that is harder to connect to. It's much simpler to run the compiler inside the Gradle process. To do that, you need to set a system property kotlin.compiler.execution.strategy to in-process in the Gradle process (note: this should be not a Gradle project property but a Java system property which can be passed by -Dkey=value or set using System.setProperty(...).
Then run a Gradle build with a command line -Dorg.gradle.debug=true to make Gradle wait for a remote debugger. I would advise for running the test project build from the terminal, not the IDE.
This will look like:
./gradlew compileKotlin -Dorg.gradle.debug=true -Dkotlin.compiler.execution.strategy=in-process
Starting a Gradle Daemon, 1 busy Daemon could not be reused, use --status for details
> Starting Daemon
(at this point, the build seems to hang, but it just waits for the debugger, so proceed below)
In the IDE where you work with the Kotlin project, put some breakpoints in the compiler code and attach the remote debugger to the Gradle process.
Note that, with the Kotlin compiler running inside the Gradle process, the latter may run out of memory sooner. Make sure the Gradle process gets enough heap space.

Kotlin compiler not found using Gradle plugin

I'm trying to upgrade some Gradle projects from Kotlin 1.0.6 to its latest version (1.1.0). However, whenever it reaches the compileKotlin task it fails:
:kiwi-common-kotlin:compileKotlin FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':kiwi-common-kotlin:compileKotlin'.
> Could not find Kotlin Compiler jar. Please specify compileKotlin.compilerJarFile
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
The project itself is divided in a bunch of subprojects. To avoid dupes, we have a separate file with the Kotlin definitions and import it on the projects using it:
File: gradle/kotlin.gradle
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"
}
}
apply plugin: org.jetbrains.kotlin.gradle.plugin.KotlinPluginWrapper
compileKotlin {
kotlinOptions.jvmTarget = "1.6"
}
And we import it in the subprojects like this:
apply from: "$rootDir/gradle/kotlin.gradle"
Since we previously tried the early preview releases and it worked seamlessly, I changed the version a couple times to see in which version the plugin broke. It turns out it works up to 1.1-M03; beginning at 1.1-M04 it shows the exact same error as in the 1.1.0 release.
We're using Gradle 2.10 in the project. Can you help me figure out whether it is a problem in our configuration? or a known issue with the Kotlin plugin itself?
It turned out to be a bug with the Gradle plugin. As pointed out by hotkeys' comment, updating to v1.1.2 fixes it.

gradle build fails cannot find sonar plugin "sonar-runner"

My gradle project cannot build. It fails with Plugin with id 'sonar-runner' not found.
Here's my build.gradle
subprojects {
apply plugin: 'sonar-runner'
}
I've refreshed my Gradle project. Then I've deleted my ~/.gradle/caches folder, but didn't work. Then I deleted my entire ~/.gradle folder, still the same error.
Any ideas please?
It's funny that gradle build doesn't run and gives me that exception, but bash gradle build runs fine, can someone clarify the difference in between? Thanks. My setup is on Mac OSX 10.11.6.
From https://docs.sonarqube.org/display/SONARQUBE51/Analyzing+with+Gradle:
Users of Gradle Sonar or Sonar Runner Plugins ? The existing Gradle
Sonar Runner and Gradle Sonar plugins, which are part of the Gradle
distribution, should no longer be used (See this official note from
the Gradleware team). The use of the Gradle SonarQube plugin is
recommended instead.
You have to use it as described at https://plugins.gradle.org/plugin/org.sonarqube
Build script snippet for use in all Gradle versions:
buildscript {
repositories {
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath "org.sonarsource.scanner.gradle:sonarqube-gradle-plugin:2.2.1"
}
}
apply plugin: "org.sonarqube"
Build script snippet for new, incubating, plugin mechanism introduced in Gradle 2.1:
plugins {
id "org.sonarqube" version "2.2.1"
}
Issue discussing this problem:
https://discuss.gradle.org/t/plugin-with-id-org-sonarqube-not-found/11588/10

gradle wrapper fails for Spring Boot application on Java 8, Gradle 3: can't find cacerts

I have encountered a problem when creating my gradlew file using the gradle wrapper command. My setup is simple: Ubuntu 14.04 + Java 8 (openjdk version "1.8.0_91") + Gradle 3.0
tutorials used:
https://spring.io/guides/gs/spring-boot/#scratch
https://docs.gradle.org/current/userguide/gradle_wrapper.html
The curious thing of this problem is that the reason why gradle wrapper fails is because the cacerts file or directory is apparently missing - but it's not (see 'check cacerts file/directory' below). Though - and please let me know if this is the issue - it's a link and not the actual file/dir. I don't know if there are any other problems given the missing cacerts error seems to be at the end of a cascade of errors, but any help to debug this would be appreciated.
My relevant files and outputs are listed below.
Cheers
AHL
build.gradle:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:1.4.0.RELEASE")
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'spring-boot'
jar {
baseName = 'gs-spring-boot'
version = '0.1.0'
}
repositories {
mavenCentral()
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
dependencies {
// tag::jetty[]
compile("org.springframework.boot:spring-boot-starter-web") {
exclude module: "spring-boot-starter-tomcat"
}
compile("org.springframework.boot:spring-boot-starter-jetty")
// end::jetty[]
// tag::actuator[]
compile("org.springframework.boot:spring-boot-starter-actuator")
// end::actuator[]
testCompile("junit:junit")
}
issue/error:
org.apache.http.ssl.SSLInitializationException: /usr/lib/jvm/java-8-openjdk-amd64/jre/lib/security/cacerts (No such file or directory)
check cacerts file/directory:
vagrant#vagrant:/vagrant/BootTutorial$ ll /usr/lib/jvm/java-8-openjdk-amd64/jre/lib/security/cacerts
lrwxrwxrwx 1 root root 27 Apr 22 13:29 /usr/lib/jvm/java-8-openjdk-amd64/jre/lib/security/cacerts -> /etc/ssl/certs/java/cacerts
vagrant#vagrant:/vagrant/BootTutorial$
output from running gradle wrapper:
vagrant#vagrant:/vagrant/BootTutorial$ gradle wrapper --gradle-version 3.0 --info
Initialized native services in: /home/vagrant/.gradle/native
Connected to daemon DaemonInfo{pid=21004, address=[61084cbc-02a2-47e1-9f7b-07d285c509b7 port:43425, addresses:[/0:0:0:0:0:0:0:1%lo, /127.0.0.1]], idle=true, lastBusy=1473685805551, context=DefaultDaemonContext[uid=b5dcb202-0edb-4f81-bd5b-bd4b828045a5,javaHome=/usr/lib/jvm/java-8-openjdk-amd64,daemonRegistryDir=/home/vagrant/.gradle/daemon,pid=21004,idleTimeout=10800000,daemonOpts=-XX:MaxPermSize=256m,-XX:+HeapDumpOnOutOfMemoryError,-Xmx1024m,-Dfile.encoding=UTF-8,-Duser.country=US,-Duser.language=en,-Duser.variant]}. Dispatching request Build{id=ac0e688f-bffe-4828-abe8-58f12354dcf6.1, currentDir=/vagrant/BootTutorial}.
Received result org.gradle.launcher.daemon.protocol.BuildStarted#6986852 from daemon DaemonInfo{pid=21004, address=[61084cbc-02a2-47e1-9f7b-07d285c509b7 port:43425, addresses:[/0:0:0:0:0:0:0:1%lo, /127.0.0.1]], idle=true, lastBusy=1473685805551, context=DefaultDaemonContext[uid=b5dcb202-0edb-4f81-bd5b-bd4b828045a5,javaHome=/usr/lib/jvm/java-8-openjdk-amd64,daemonRegistryDir=/home/vagrant/.gradle/daemon,pid=21004,idleTimeout=10800000,daemonOpts=-XX:MaxPermSize=256m,-XX:+HeapDumpOnOutOfMemoryError,-Xmx1024m,-Dfile.encoding=UTF-8,-Duser.country=US,-Duser.language=en,-Duser.variant]} (build should be starting).
The client will now receive all logging from the daemon (pid: 21004). The daemon log file: /home/vagrant/.gradle/daemon/3.0/daemon-21004.out.log
Starting 7th build in daemon [uptime: 39 mins 8.147 secs, performance: 91%]
Executing build with daemon context: DefaultDaemonContext[uid=b5dcb202-0edb-4f81-bd5b-bd4b828045a5,javaHome=/usr/lib/jvm/java-8-openjdk-amd64,daemonRegistryDir=/home/vagrant/.gradle/daemon,pid=21004,idleTimeout=10800000,daemonOpts=-XX:MaxPermSize=256m,-XX:+HeapDumpOnOutOfMemoryError,-Xmx1024m,-Dfile.encoding=UTF-8,-Duser.country=US,-Duser.language=en,-Duser.variant]
Starting Build
Settings evaluated using settings file '/master/settings.gradle'.
Projects loaded. Root project using build file '/vagrant/BootTutorial/build.gradle'.
Included projects: [root project 'BootTutorial']
Evaluating root project 'BootTutorial' using build file '/vagrant/BootTutorial/build.gradle'.
FAILURE: Build failed with an exception.
* What went wrong:
A problem occurred configuring root project 'BootTutorial'.
> Could not resolve all dependencies for configuration ':classpath'.
> Could not resolve org.springframework.boot:spring-boot-gradle-plugin:1.4.0.RELEASE.
Required by:
:BootTutorial:unspecified
> Could not resolve org.springframework.boot:spring-boot-gradle-plugin:1.4.0.RELEASE.
> Could not get resource 'https://repo1.maven.org/maven2/org/springframework/boot/spring-boot-gradle-plugin/1.4.0.RELEASE/spring-boot-gradle-plugin-1.4.0.RELEASE.pom'.
> org.apache.http.ssl.SSLInitializationException: /usr/lib/jvm/java-8-openjdk-amd64/jre/lib/security/cacerts (No such file or directory)
* Try:
Run with --stacktrace option to get the stack trace. Run with --debug option to get more log output.
BUILD FAILED
Total time: 1.391 secs
Received result Failure[value=org.gradle.initialization.ReportedException: org.gradle.internal.exceptions.LocationAwareException: A problem occurred configuring root project 'BootTutorial'.] from daemon DaemonInfo{pid=21004, address=[61084cbc-02a2-47e1-9f7b-07d285c509b7 port:43425, addresses:[/0:0:0:0:0:0:0:1%lo, /127.0.0.1]], idle=true, lastBusy=1473685805551, context=DefaultDaemonContext[uid=b5dcb202-0edb-4f81-bd5b-bd4b828045a5,javaHome=/usr/lib/jvm/java-8-openjdk-amd64,daemonRegistryDir=/home/vagrant/.gradle/daemon,pid=21004,idleTimeout=10800000,daemonOpts=-XX:MaxPermSize=256m,-XX:+HeapDumpOnOutOfMemoryError,-Xmx1024m,-Dfile.encoding=UTF-8,-Duser.country=US,-Duser.language=en,-Duser.variant]} (build should be done).
vagrant#vagrant:/vagrant/BootTutorial$
You are probably hitting a bug that left your symlink to the certs dangling as reported here and here. One suggested solution is to reinstall the ca-certificates-java package. Like this:
$ sudo dpkg --purge --force-depends ca-certificates-java
$ sudo apt-get install ca-certificates-java

Resources