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

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.

Related

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

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

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

gradle issue on ./gradlew eclipse vs. gradle plugin

ok, 3 bugs below I 'think' but if they are not let me know. (I do LOVE the customizability of gradle and these are corner case bugs for sure but still inconsistent behaviors)
gradle version 2.14.1
Eclipse Neon 4.6.0 build id 20160613-1800
Buildship, Eclipse Plugins for gradle 1.0.20v20160901-0734
I LOVE making things seamless so I really wanted to make things seamless on using eclipse with this project https://github.com/deanhiller/webpiecesExample as a test run.
BUG 1: Instead, I found a bug in the eclipse buildship gradle plugin that does not bring in -parameters to the project settings like ./gradlew eclipse does :(.
I have the following that makes my gradle compile with parameters (and ./gradlew eclipse generates the correct settings file while buildship ecilpse gradle plugin does not)
[compileJava, compileTestJava]*.options.collect {options ->
options.compilerArgs.add '-parameters'
}
BUG 2: so then I switch to ./gradlew eclipse. That then has a different bug in that it generates two src/main/java when using a section like this.....
sourceSets {
//For testing, we need to put the html files on the classpath which are co-located with the controllers
extraTest {
resources {
srcDirs = ["src/main/java"]
includes = ["**/*.html", "**/*.tag"]
}
}
test {
resources {
//This ADDS src/test/java/**/*.html and we still read in src/test/resources/**
source extraTest.resources
}
}
}
BUG 3: In trying to figure this all out, I finally found out gradlew cleanEclipse does not clean stuff that was generated by gradlew eclipse specifically the .settings folder :(. I basically can do a ./gradlew eclipse and then gradlew cleanEclipse and they don't delete what was created :(.
FEATURE REQUEST 1: The application plugin I had to hack like this....(definitely read my comments as the solution ended up not working and I had to hack it differently).
How to configure gradle application plugin to set my user.dir to the location of the script?
You should totally be able to tell the application plugin that one desires the application directory to be where the program starts no matter what directory I start the application from....that was very frustrating to fix all that.
I still love gradle. I am just getting very down and dirty in the details here and hope that eventually these nitpicks can be fixed.

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.

What should be in the build.gradle file to support imports of the standard groovy libraries

I had created a groovy project. It worked by itself.
After some additions I had to add a new jar of a new library into the imports.
While the whole workspace runs on Gradle, I added the appropriate Maven reference to the gradle.build file.
After running gradle cleanEclipse Eclipse the new library works OK.
But. All project references to the Groovy libraries disappeared. Foolish me, I had to put some references to them into the gradle.build, too.
The list of libraries:
groovy.util.slurpersupport
groovy.xml
org.codehaus.groovy.tools.xml
groovy.lang
But I don't know how to include them into gradle.build. I can't found them in maven repository. And even so, I have them installed in my Eclipse, and I should take these. And I can't google any help, because gradle groovy gives the results on how to call gradle from groovy, not vice versa.
Moving from plain Groovy to Gradle won't help, it is really about gradle support for calling a java library from groovy.
I have nothing against getting dependencies from Maven rep., but I don't know how to do it in my case - The problem is, that I have Eclipse 3.6. And I should use the last version of groovy for Eclipse 3.6. So, I have installed it from http://dist.codehaus.org/groovy/distributions/greclipse/snapshot/e3.6/. And I don't know what is the equivalent version in Maven - there is no info about it.
There was some error in the groovy in Eclipse installation. Now after running gradle cleanEclipse Eclipse while build.gradle has NO dependencies to groovy, almost everything runs OK, I only have to add the groovy nature to the project

Resources