IntelliJ "Deprecated Gradle features" - how to reproduce on command line? - gradle

When I reload my Gradle Project in IntelliJ, I get the following output:
Deprecated Gradle features were used in this build, making it incompatible with Gradle 8.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/7.0/userguide/command_line_interface.html#sec:command_line_warnings
However, running gradle commands on the command line, such as tasks or build does not produce this output, even with --warning-mode all.
In order to identify the deprecated features, how can I reproduce what IntelliJ is doing on the command line, or do the equivalent of passing --warning-mode all to Gradle via IntelliJ?
I'm using Gradle 7.0 with the Gradle wrapper, and IntelliJ is set to use the version in gradle-wrapper.properties.

To have IntelliJ run with the warning mode, add it to the gradle.properties file (create the file if it does not exist):
org.gradle.warning.mode=all
I have a new Java Gradle project generated with IntelliJ and run the main from the IDE. When running with this option Gradle explains what's wrong, and indicates the location in the .gradle script IntelliJ is using containing the deprecated property:
Configure project : The JavaExec.main property has been deprecated. This is scheduled to be removed in Gradle 8.0. Please use the
mainClass property instead. See
https://docs.gradle.org/7.4/dsl/org.gradle.api.tasks.JavaExec.html#org.gradle.api.tasks.JavaExec:main
for more details. at
StartApplication_main__1_87e3b1xfpa17mk8z0q8rqeouu$_run_closure1$_closure2$_closure3.doCall(C:\Users\...\AppData\Local\Temp\StartApplication_main__1.gradle:23)
(Run with --stacktrace to get the full stack trace of this
deprecation warning.)
The cause of your deprecation warning may be different (like having jcenter() as suggested by #amitesh-mondal ). Adding the warning property will tell you the cause.

in settings.gradle comment out like
// jcenter() // Warning: this repository is going to shut down soon
This is going to solve the issue

Related

Gradle's dependency cache may be corrupt in Intellij Idea

Today when I refresh the spring boot project in Intellij Idea IntelliJ IDEA 2022.1.1 (Ultimate Edition), show error like this:
Unable to find method ''org.gradle.api.tasks.SourceSetContainer org.gradle.api.plugins.JavaPluginExtension.getSourceSets()''
'org.gradle.api.tasks.SourceSetContainer org.gradle.api.plugins.JavaPluginExtension.getSourceSets()'
Gradle's dependency cache may be corrupt (this sometimes occurs after a network connection timeout.)
Re-download dependencies and sync project (requires network)
The state of a Gradle build process (daemon) may be corrupt. Stopping all Gradle daemons may solve this problem.
Stop Gradle build processes (requires restart)
Your project may be using a third-party plugin which is not compatible with the other plugins in the project or the version of Gradle requested by the project.
In the case of corrupt Gradle processes, you can also try closing the IDE and then killing all Java processes.
I have already tried:
restart IDE
invalidate cache and restart IDE
stop gradle build process and restart IDE
remove the ./gradle/wrapper/dist folder
change the gradle version in gradle/wrapper folder
both did not fixed this problem, why did this happen? what should I do to fixed this problem? BTW, when I using this command ./gradlew clean :dolphin-post:dolphin-post-service:build -x test to build project in terminal:
➜ dolphin-post git:(master) ✗ ./gradlew clean :dolphin-post:dolphin-post-service:build -x test
Downloading https://services.gradle.org/distributions/gradle-7.4.1-all.zip
...............10%...............20%...............30%...............40%...............50%................60%...............70%...............80%...............90%...............100%
Welcome to Gradle 7.4.1!
Here are the highlights of this release:
- Aggregated test and JaCoCo reports
- Marking additional test source directories as tests in IntelliJ
- Support for Adoptium JDKs in Java toolchains
For more details see https://docs.gradle.org/7.4.1/release-notes.html
Starting a Gradle Daemon (subsequent builds will be faster)
> Configure project :dolphin-acientbay
/Users/xiaoqiangjiang/source/reddwarf/backend/retire
> Configure project :dolphin-post
/Users/xiaoqiangjiang/source/reddwarf/backend/retire/build.gradle'
> Configure project :dolphin-template
/Users/xiaoqiangjiang/source/reddwarf/backend/retiretemplate/build.gradle'
> Task :dolphin-common:compileJava
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
> Task :dolphin-post:dolphin-post-service:compileJava
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
Deprecated Gradle features were used in this build, making it incompatible with Gradle 8.0.
You can use '--warning-mode all' to show the individual deprecation warnings and determine if they come from your own scripts or plugins.
See https://docs.gradle.org/7.4.1/userguide/command_line_interface.html#sec:command_line_warnings
BUILD SUCCESSFUL in 1m 58s
17 actionable tasks: 16 executed, 1 up-to-date
works fine.

Gradle wrapper fails to find javafx on build, built-in gradle works okay on build

The issue is that executing gradle commands via the wrapper will cause the compileKotlin step to fail with different mentions that it is unable to find javafx-related classes/packages.
I'm setting up the whole project structure so that all the build system is not dependent on the IDE but rather relies on using the wrapper to execute all the build.
But executing a gradlew.bat build on the command line will fail with the mentioned errors. However, executing a "build" via the embedded Gradle in Intellij works. (attached pictures)
A few things to mention:
kotlin version 1.3.50 (latest version)
gradle version in wrapper properties is 5.6.2
Build failure pic:
Build working with Gradle from Intellij:
Build from Intellij button:
Gradle config in Intellij:
I have already tried plenty of suggestions mentioned on several topics related to this one (Invalidated caches + Restart, re-importing project, generating the wrapper again, all the usual solutions you will see for this issue). None of them worked, so the issue remains. I tried switching between versions of Gradle and running the wrapper again and that didn't work, it seems that version specified for the wrapper and the Gradle distribution it pulls down does not matter since the build fails with exactly the same error on all versions.
Note that this happened quite recently after an update of Intellij Idea from version 2019.2.2 to 2019.2.3, I really hope this isn't the root issue behind it.
This is not the only project with Gradle kotlin-dsl using javafx that is failing right now: even creating a new empty project via the tornadofx-plugin for Intellij and migrating it to the kotlin-dsl will yield the same results: compileKotlin task will fail. Besides that, several older projects with gradle kotlin-dsl that were building fine from the wrapper suddenly started out giving the same error.
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import edu.sc.seis.launch4j.tasks.DefaultLaunch4jTask
plugins {
application
id("edu.sc.seis.launch4j") version "2.4.6"
kotlin("jvm") version "1.3.50"
}
group = "genericdesktopapp"
version = "1.0-SNAPSHOT"
application {
mainClassName = "root/RootKt"
}
repositories {
mavenCentral()
mavenLocal()
}
dependencies {
implementation(kotlin(module = "reflect", version = "1.3.50"))
implementation(kotlin("stdlib-jdk8"))
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.0-RC")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-javafx:1.3.0-RC")
implementation("org.slf4j:slf4j-api:1.7.21")
implementation("com.lmax:disruptor:3.3.4")
implementation("org.apache.logging.log4j:log4j-slf4j-impl:2.6.2")
implementation("org.apache.logging.log4j:log4j-api:2.6.2")
implementation("org.apache.logging.log4j:log4j-core:2.6.2")
implementation("commons-io:commons-io:2.6")
implementation("org.apache.commons:commons-text:1.6")
implementation("com.github.salomonbrys.kodein:kodein:4.1.0")
implementation("commons-validator:commons-validator:1.6")
implementation("no.tornado:tornadofx:1.7.17")
testImplementation("org.junit.jupiter:junit-jupiter-api:5.1.0")
testRuntime("org.junit.jupiter:junit-jupiter-engine:5.1.0")
}
tasks.withType<KotlinCompile> {
kotlinOptions.jvmTarget = "1.8"
}
tasks.withType<DefaultLaunch4jTask> {
outfile = "GenericToolbox.exe"
mainClassName = "root.Root"
productName = "GenericToolbox"
}
I expect that when I run in the command line gradlew.bat build or ./gradlew build for it to complete normally and find the related classes from javafx, like it happens when using Intellij Gradle build command.
This issue should not even happen since I'm keeping everything at java-8, I know this issue is supposed to happen to versions beyond 8. I'm also seeing in the gradle caches the stdlib-jdk7 from kotlin, I have nowhere nothing related to jdk7 specified in my Intellij configurations or in the build script, so that is also something weird happening. (even cache reset made gradle pull it back in the cache, so I'm thinking it's probably the embedded kotlin compiler from gradle that is that version).
Edit: An easy way of reproducing it (just tested it right now).
Open a command line and create a new project with gradle kotlin dsl:
mkdir testproject
cd testproject
gradle init --dsl kotlin
On the project that was generated, run the gradlew.bat build or ./gradlew build and see the compileKotlin working okay and the build is successful.
On the same project, in the generated App.kt file, in the main function, add a simple val stage = Stage() (imported from javafx).
Run again the gradlew.bat build and see that it now fails since it doesn't find javafx.
I have managed to find a way around this issue, however, it's not a proper solution since I still haven't found the cause for why that was happening, but I'll post it in case anyone else will have this issue and maybe it will be helpful.
The solution is (weirdly enough) to specify the jdk version that gradle will use when running the commands through the wrapper:
gradlew.bat build -Dorg.gradle.java.home=---path-to-jdk---
I have checked my environment variables and the java home variable already points to that same location, so somehow I believe gradle doesn't find the java home and uses something embedded (which is most likely something above java 8) which produces that error. Running through the Intellij gradle works because it is using the embedded jdk in Intellij which is also java8, so that explains why they were working through the Intellij build button from the Gradle side-window.
If anyone finds the root cause or has some other suggestion, please, feel free to share your knowledge.

Missing Gradle JavaDoc in IDEA

I would like to view the JavaDocs for Gradle classes while I am editing a Gradle file in IntelliJ IDEA. I have the Gradle plugin installed (version 172.4572.19, up-to-date as far as I can tell) and the syntax highlighting works. I'm using Gradle 4.8.1 installed via brew. When I try to view JavaDocs for the entity under my cursor, I get something like this:
As you can see, the class and package names are provided, but none of the JavaDoc is there. Furthermore, none of the methods for configuration are listed, making this near useless.
How do I get IDEA to show me more helpful and complete JavaDocs for entities in Gradle files?
In my case it turned out that my Gradle installation did not contain the javadocs at all!
When you install Gradle using Homebrew, as stated in the documentation you have to add the --with-all flag if you want to install the javadocs. So you should install like this:
brew install gradle --with-all
Once this was done, I also had to reimport Gradle projects before IDEA would let me view JavaDocs.
You can add Gradle wrapper for project (after this enable it in IDE in Settings/Preferences | Build, Execution, Deployment | Build Tools | Gradle | Use default gradle wrapper (recommended)) and use Gradle distribution with sources.
When you create new project there is an option configure it:
After this documentation will appear when editing build.gradle file:

Error: DefaultOperationDescriptor#2b878eea already available in Android Studio

Failed to complete Gradle Execution
When I try to Sync Gradle with Project Files, the error mentioned below appears
Android Studio version that I am using is 3.0.1, Gradle Build 4.1-all.zip
FYI, I have already tried ->Build->Clean Project and Invalidate Cache & Restart and one more thing is that there is no error in my code.
Message Error:
Information:Gradle tasks [:app:generateDebugSources, :app:generateDebugAndroidTestSources, :app:mockableAndroidJar]
Error:Failed to complete Gradle execution.
Cause:
Operation org.gradle.tooling.internal.provider.events.DefaultOperationDescriptor#86028ba already available.
BUILD SUCCESSFUL in 8s
Information:1 error
Information:0 warnings
But When I try to Run on my Emulator
The error below appears
Message Error At Run Time
Information:Gradle tasks [:app:assembleDebug]
E:\Android Game App\app\build.gradle
Error:(1, 1) A problem occurred evaluating project ':Android Game App:app'.
Failed to apply plugin [id 'com.android.application']
Due to a limitation of Gradle new variant-aware dependency management, loading the Android Gradle plugin in different class loaders leads to a build error.
This can occur when the buildscript classpaths that contain the Android Gradle plugin in sub-projects, or included projects in the case of composite builds, are set differently.
To resolve this issue, add the Android Gradle plugin to only the buildscript classpath of the top-level build.gradle file.
In the case of composite builds, also make sure the build script classpaths that contain the Android Gradle plugin are identical across the main and included projects.
If you are using a version of Gradle that has fixed the issue, you can disable this check by setting android.enableBuildScriptClasspathCheck=false in the gradle.properties file.
To learn more about this issue, go to https://d.android.com/r/tools/buildscript-classpath-check.html.
Information:BUILD FAILED in 16s
Information:1 error
Information:0 warnings
Information:See complete output in console
Nothing found on Google! Any help would be highly encouraged???
The key to the problem is this line. Maybe due to a project.all in root build.gradle or you are using composite builds.
This can occur when the build script classpaths that contain the Android Gradle plugin in sub-projects,
or included projects in the case of composite builds, are set differently.
that mean in all yours build.gradle you have more than one this line
buildscript {
dependencies {
classpath "com.android.tools.build:gradle:x.y.z"
}
}
what this means is that with the introduction of Android Gradle Plugin 3.Y.Z and the new way of handling dependencies,
if you mix in the same project 2 projects with different plugin version (one with a 2.3 and other with 3.0.1) you will get dragons while compiling.
And this error it's a way to force developer to check it and opt-out once detected and solved.
how to solve it, first ensure you don't use a android gradle plugin below 3.0.1 and use the new dependencies configurations, and add this property on every gradle.properties you have.
android.enableBuildScriptClasspathCheck=false
with that you can now compile
one example could be found at realm sample repo they use a allprojects block that include android gradle plugin on every module. and solve it adding previus gradle property at root gradle.properties

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.

Resources