I tried my first program in Gradle but I got an error. I wrote a hello world script but I am unable to run it.
My gradle details are:
------------------------------------------------------------
Gradle 2.0
------------------------------------------------------------
Build time: 2014-07-01 07:45:34 UTC
Build number: none
Revision: b6ead6fa452dfdadec484059191eb641d817226c
Groovy: 2.3.3
Ant: Apache Ant(TM) version 1.9.3 compiled on December 23 2013
JVM: 1.8.0_11 (Oracle Corporation 25.11-b03)
OS: Windows 7 6.1 x86
My build.gradle is:
task hello << {
println 'Hello world!'
}
When I run gradle -q --info hello, I get the following error:
Starting Build
Settings evaluated using empty settings script.
Projects loaded. Root project using build file 'D:\Gradle\build.gradle'.
Included projects: [root project 'Gradle']
Evaluating root project 'Gradle' using build file 'D:\Gradle\build.gradle'.
FAILURE: Build failed with an exception.
* Where:
Build file 'D:\Gradle\build.gradle' line: 1
* What went wrong:
A problem occurred evaluating root project 'Gradle'.
> Could not find property 'hello' on root project 'Gradle'.
* Try:
Run with --stacktrace option to get the stack trace. Run with --debug option to
get more log output.
BUILD FAILED
Total time: 7.048 secs
The stacktrace is as follows:
Exception is:
org.gradle.api.GradleScriptException: A problem occurred evaluating root project
'Gradle'.
at org.gradle.groovy.scripts.internal.DefaultScriptRunnerFactory$ScriptR
unnerImpl.run(DefaultScriptRunnerFactory.java:54)
at org.gradle.configuration.DefaultScriptPluginFactory$ScriptPluginImpl.
apply(DefaultScriptPluginFactory.java:187)
at org.gradle.configuration.project.BuildScriptProcessor.execute(BuildSc
riptProcessor.java:39)
at org.gradle.configuration.project.BuildScriptProcessor.execute(BuildSc
riptProcessor.java:26)
at org.gradle.configuration.project.ConfigureActionsProjectEvaluator.eva
luate(ConfigureActionsProjectEvaluator.java:34)
at org.gradle.configuration.project.LifecycleProjectEvaluator.evaluate(L
ifecycleProjectEvaluator.java:55)
at org.gradle.api.internal.project.AbstractProject.evaluate(AbstractProj
ect.java:470)
at org.gradle.api.internal.project.AbstractProject.evaluate(AbstractProj
ect.java:79)
at org.gradle.configuration.DefaultBuildConfigurer.configure(DefaultBuil
dConfigurer.java:31)
at org.gradle.initialization.DefaultGradleLauncher.doBuildStages(Default
GradleLauncher.java:128)
at org.gradle.initialization.DefaultGradleLauncher.doBuild(DefaultGradle
Launcher.java:105)
at org.gradle.initialization.DefaultGradleLauncher.run(DefaultGradleLaun
cher.java:85)
at org.gradle.launcher.exec.InProcessBuildActionExecuter$DefaultBuildCon
troller.run(InProcessBuildActionExecuter.java:81)
at org.gradle.launcher.cli.ExecuteBuildAction.run(ExecuteBuildAction.jav
a:33)
at org.gradle.launcher.cli.ExecuteBuildAction.run(ExecuteBuildAction.jav
a:24)
at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProce
ssBuildActionExecuter.java:39)
at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProce
ssBuildActionExecuter.java:29)
at org.gradle.launcher.cli.RunBuildAction.run(RunBuildAction.java:50)
at org.gradle.internal.Actions$RunnableActionAdapter.execute(Actions.jav
a:171)
at org.gradle.launcher.cli.CommandLineActionFactory$ParseAndBuildAction.
execute(CommandLineActionFactory.java:237)
at org.gradle.launcher.cli.CommandLineActionFactory$ParseAndBuildAction.
execute(CommandLineActionFactory.java:210)
at org.gradle.launcher.cli.JavaRuntimeValidationAction.execute(JavaRunti
meValidationAction.java:35)
at org.gradle.launcher.cli.JavaRuntimeValidationAction.execute(JavaRunti
meValidationAction.java:24)
at org.gradle.launcher.cli.CommandLineActionFactory$WithLogging.execute(
CommandLineActionFactory.java:206)
at org.gradle.launcher.cli.CommandLineActionFactory$WithLogging.execute(
CommandLineActionFactory.java:169)
at org.gradle.launcher.cli.ExceptionReportingAction.execute(ExceptionRep
ortingAction.java:33)
at org.gradle.launcher.cli.ExceptionReportingAction.execute(ExceptionRep
ortingAction.java:22)
at org.gradle.launcher.Main.doAction(Main.java:33)
at org.gradle.launcher.bootstrap.EntryPoint.run(EntryPoint.java:45)
at org.gradle.launcher.bootstrap.ProcessBootstrap.runNoExit(ProcessBoots
trap.java:54)
at org.gradle.launcher.bootstrap.ProcessBootstrap.run(ProcessBootstrap.j
ava:35)
at org.gradle.launcher.GradleMain.main(GradleMain.java:23)
Caused by: groovy.lang.MissingPropertyException: Could not find property 'hello'
on root project 'Gradle'.
at org.gradle.api.internal.AbstractDynamicObject.propertyMissingExceptio
n(AbstractDynamicObject.java:43)
at org.gradle.api.internal.AbstractDynamicObject.getProperty(AbstractDyn
amicObject.java:35)
at org.gradle.api.internal.CompositeDynamicObject.getProperty(CompositeD
ynamicObject.java:94)
at org.gradle.groovy.scripts.BasicScript.propertyMissing(BasicScript.jav
a:66)
at build_4hki6gadurnm5c9ejslud0e844.run(D:\Gradle\build.gradle:1)
at org.gradle.groovy.scripts.internal.DefaultScriptRunnerFactory$ScriptR
unnerImpl.run(DefaultScriptRunnerFactory.java:52)
... 31 more
BUILD FAILED
Total time: 26.219 secs
amicObject.java:35)
at org.gradle.api.internal.CompositeDynamicObject.getProperty(CompositeD
ynamicObject.java:94)
at org.gradle.groovy.scripts.BasicScript.propertyMissing(BasicScript.jav
a:66)
at build_4hki6gadurnm5c9ejslud0e844.run(D:\Gradle\build.gradle:1)
at org.gradle.groovy.scripts.internal.DefaultScriptRunnerFactory$ScriptR
unnerImpl.run(DefaultScriptRunnerFactory.java:52)
... 31 more
I know it's a little bit late, but for those who face the same problem (as you and me) i'll post my solution.
The problem is in the build.gradle encoding, i'm running windows (default encoding ansi) and my build.gradle was UTF-8, I've changed the build.gradle encoding to match my OS encoding and everything works fine now.
To resolve the issue, try to build your project first by using the command:
gradle build
Once this is done, run the task inside your gradle file by saying:
gradle -q hello
gradle -q --info hello
Hope this helps!
I too got this problem when I wrote my first gradle project. It is because of your file encoding. Do not copy the helloword project. Type these words by your self.
task helloword << {
println 'pringln hello word'
}
All I had to do was update kotlin version in gradle, I changed it from "1.2.40" to "1.3.72"
buildscript {
ext.kotlin_version = '1.3.72'
repositories {
mavenCentral()
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
Related
I'm using Micronaut 3.1.3 together with Gradle 7.2 to build my project.
After switching to Gradle 7.3, built breaks emitting some context-free error message:
$ ./gradlew clean build
Executed by Gradle 7.3
- using Java 11.0.13
- using Kotlin 1.5.31
- using Groovy 3.0.9
FAILURE: Build failed with an exception.
* What went wrong:
A problem occurred configuring root project '[PROJECT]'.
> The value for this property is final and cannot be changed any further.
With --stacktrace a very long trace appears. The following excerpt makes me guess
that the problem might lay in the Micronaut plugin:
* Exception is:
org.gradle.api.ProjectConfigurationException: A problem occurred configuring root project '[PROJECT]'.
at org.gradle.configuration.project.LifecycleProjectEvaluator.wrapException(LifecycleProjectEvaluator.java:75)
at org.gradle.configuration.project.LifecycleProjectEvaluator.addConfigurationFailure(LifecycleProjectEvaluator.java:68)
at org.gradle.configuration.project.LifecycleProjectEvaluator.access$400(LifecycleProjectEvaluator.java:51)
[...]
at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:61)
Caused by: java.lang.IllegalStateException: The value for this property is final and cannot be changed any further.
at org.gradle.api.internal.provider.AbstractProperty$FinalizedValue.beforeMutate(AbstractProperty.java:489)
at org.gradle.api.internal.provider.AbstractProperty.assertCanMutate(AbstractProperty.java:263)
at org.gradle.api.internal.provider.AbstractProperty.setSupplier(AbstractProperty.java:212)
at org.gradle.api.internal.provider.DefaultProperty.set(DefaultProperty.java:71)
at org.gradle.api.tasks.testing.Test.useTestFramework(Test.java:979)
at org.gradle.api.tasks.testing.Test.useJUnitPlatform(Test.java:1049)
at org.gradle.api.tasks.testing.Test.useJUnitPlatform(Test.java:1032)
at io.micronaut.gradle.MicronautLibraryPlugin.lambda$null$1(MicronautLibraryPlugin.java:103)
at org.gradle.configuration.internal.DefaultUserCodeApplicationContext$CurrentApplication$1.execute(DefaultUserCodeApplicationContext.java:123)
[...]
at org.gradle.api.internal.DefaultDomainObjectCollection.withType(DefaultDomainObjectCollection.java:201)
at io.micronaut.gradle.MicronautLibraryPlugin.lambda$apply$4(MicronautLibraryPlugin.java:101)
at org.gradle.configuration.internal.DefaultUserCodeApplicationContext$CurrentApplication$1.execute(DefaultUserCodeApplicationContext.java:123)
[...]
at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:61)
Cause "problem occurred configuring root project" I'm not sure which part of my
build.gradle raises the problem. So following my first guess regarding Micronaut
plugin, here is an excerpt telling you the list of plugins in use and config of this plugin:
plugins {
id('org.jetbrains.kotlin.jvm') version "${kotlinVersion}"
id('groovy')
id('org.jetbrains.kotlin.kapt') version "${kotlinVersion}"
id('com.github.johnrengelman.shadow') version '7.+'
id('io.micronaut.application') version '2.+'
id('org.jetbrains.kotlin.plugin.allopen') version "${kotlinVersion}"
id('com.google.cloud.tools.jib') version '3.+'
id('org.openapi.generator') version '5.+'
id('com.heroku.sdk.heroku-gradle') version '2.+'
}
[...]
micronaut {
runtime('netty')
testRuntime('spock2')
processing {
incremental(true)
annotations('[PACKAGE]')
}
}
Maybe this gives enough information to tackle down the cause of the problem?
If not please let me know.
Regards
I hit the same issue with my Java build and asked for help on gradle slack channel. It found to be a change in Gradle 7.3 behavior.
This issue contains an explanation of the cause and how to fix it.
It helped me to solve the issue with my build: I had options defined in one of the test tasks and then useJUnitPlatform was applied across all test tasks afterwards using this snippet:
tasks.withType(Test).configureEach {
useJUnitPlatform() // <-- this line was breaking the build
}
This broke the build after migrating to Gradle 7.3. Removing options solved the problem for me.
Here's an issue requesting to convert this breaking behavior to a warning in Gradle 7.3 and make it a breaking change in 8.0.
FYI: Upgrade to Gradle 7.3.1 brings back successful builds.
I have set up my new PC and I'am already having some problems with Flutter. It used to run fine on my older PC.
I've installed Android Studio, Android SDK, Flutter, VS Code with Dart and Flutter plugins, and after that created new flutter project. After connecting my phone to PC and hitting F5 I'm getting this error:
* Error running Gradle:
ProcessException: Process "D:\FlutterProjects\quotes\android\gradlew.bat" exited abnormally:
Starting a Gradle Daemon (subsequent builds will be faster)
FAILURE: Build failed with an exception.
* What went wrong:
Unable to start the daemon process.
This problem might be caused by incorrect configuration of the daemon.
For example, an unrecognized jvm option is used.
Please refer to the user guide chapter on the daemon at https://docs.gradle.org/4.10.2/userguide/gradle_daemon.html
Please read the following process output to find out more:
-----------------------
Error: Could not find or load main class org.gradle.launcher.daemon.bootstrap.GradleDaemon
* 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.
* Get more help at https://help.gradle.org
Command: D:\FlutterProjects\quotes\android\gradlew.bat app:properties
Please review your Gradle project setup in the android/ folder.
Flutter doctor looks fine.
Here are my gradle-wrapper.properties:
#Fri Jun 23 08:50:38 CEST 2017
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.2-all.zip
And gradle.properties:
org.gradle.jvmargs=-Xmx1536M
org.gradle.daemon=true
org.gradle.parallel=true
And the last thing, build.gradle:
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.2.1'
}
}
allprojects {
repositories {
google()
jcenter()
}
}
rootProject.buildDir = '../build'
subprojects {
project.buildDir = "${rootProject.buildDir}/${project.name}"
}
subprojects {
project.evaluationDependsOn(':app')
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Can anyone help me with that problem?
run
flutter clean
it will clean your current build folder and cache, then when you run your Flutter App, a new Build folder will be created.
in most cases it fix it.
I have a Groovy project which is mostly built using Java 7, but I want to build one module using Java 8. Following the documentation for the gradle Groovy plugin, I have added the following to build.gradle for the module:
// Set up for using Java 8
def java8Home = getJava8Home()
def javaExecutable = new File(java8Home, 'bin/java')
println "Java executable = $javaExecutable"
tasks.withType(AbstractCompile) {
options.with {
fork = true
forkOptions.javaHome = file(java8Home)
}
println 'COMPILE ' + name + ': ' + options.forkOptions.javaHome
}
tasks.withType(Test) {
executable = javaExecutable
println ' TEST ' + name + ': ' + executable
}
Now when I run gradlew project-name:browserTest, I see lines like the following
Java executable = ...//jdk1.8.0_144.jdk/Contents/Home/bin/java
COMPILE compileBrowserTestGroovy: .../jdk1.8.0_144.jdk/Contents/Home
...
TEST browserTest: .../jdk1.8.0_144.jdk/Contents/Home/bin/java
...
So I expect a forked compile daemon for compileBrowserTestGroovy using Java 8. However I get an error (Unsupported major.minor version 52.0)showing that it is using Java 7, and I see the following when running with -debug
16:14:03.760 [INFO] [org.gradle.process.internal.DefaultExecHandle] Starting process 'Gradle Worker Daemon 1'. Working directory: /Users/alasdair/workspace/project-name Command: /Library/Java/JavaVirtualMachines/jdk1.7.0_80.jdk/Contents/Home/bin/java -Djava.security.manager=worker.org.gradle.process.internal.worker.child.BootstrapSecurityManager -Dfile.encoding=UTF-8 -Duser.country=GB -Duser.language=en -Duser.variant -cp /Users/alasdair/.gradle/caches/3.5/workerMain/gradle-worker.jar worker.org.gradle.process.internal.worker.GradleWorkerMain 'Gradle Worker Daemon 1'
What am I doing wrong?
UPDATE:
I created a small test project with a java 7 and java 8 module. Set up as suggested it works perfectly. The difference seems to be around 'Worker Daemons' ie looking at the debug output above gradle is starting process 'Gradle Worker Daemon 1' (using java 7), whereas the log from the test project shows
16:10:30.559 [DEBUG] [org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter] Executing actions for task ':java-8:compileJava'.
16:10:30.581 [DEBUG] [org.gradle.api.internal.tasks.compile.NormalizingJavaCompiler] Compiler arguments: -source 1.8 -target 1.8 -d /Users/alasdair/workspace/test-project/java-8/build/classes/main -g -sourcepath -proc:none -XDuseUnsharedTable=true -classpath /Users/alasdair/workspace/test-project/java-8/src/main/java/Foo.java
16:10:30.582 [INFO] [org.gradle.api.internal.tasks.compile.CommandLineJavaCompiler] Compiling with Java command line compiler '/Library/Java/JavaVirtualMachines/jdk1.8.0_144.jdk/Contents/Home/bin/javac'.
16:10:30.597 [INFO] [org.gradle.process.internal.DefaultExecHandle] Starting process 'command '/Library/Java/JavaVirtualMachines/jdk1.8.0_144.jdk/Contents/Home/bin/javac''. Working directory: /Users/alasdair/workspace/test-project/java-8 Command: /Library/Java/JavaVirtualMachines/jdk1.8.0_144.jdk/Contents/Home/bin/javac #/Users/alasdair/workspace/test-project/java-8/build/tmp/compileJava/java-compiler-args.txt
So it seems to be forking and starting a compile with the correct jvm. Why is my main build starting these 'Daemon Workers'? I have in gradle.properties org.gradle.daemon=false. I have tried various other things but this remains the question, as it seems to be just creating and using a new daemon instead of forking with the correct jvm as requested
I've a Kotlin Spring Boot project here. It has some tests, which run just fine from IntelliJ, but when I run from command line, fail with the following errors.
BUILD FAILED in 1m 12s
7 actionable tasks: 7 executed
asarkar:license-report-kotlin$ ./gradlew clean test
> Task :compileKotlin
Using kotlin incremental compilation
> Task :compileTestKotlin
Using kotlin incremental compilation
> Task :test
2017-07-16 21:43:06.345 INFO 2956 --- [ Thread-13] s.c.a.AnnotationConfigApplicationContext : Closing org.springframework.context.annotation.AnnotationConfigApplicationContext#54fa5525: startup date [Sun Jul 16 21:42:04 PDT 2017]; root of context hierarchy
org.abhijitsarkar.ApplicationTest > testEndToEnd FAILED
java.lang.AssertionError at ApplicationTest.kt:83
org.abhijitsarkar.service.GradleAgentTest > initializationError FAILED
java.lang.ClassNotFoundException
org.abhijitsarkar.service.JGitAgentTest > initializationError FAILED
java.lang.ClassNotFoundException
org.abhijitsarkar.service.LinkVerifierTest > initializationError FAILED
java.lang.ClassNotFoundException
4 tests completed, 4 failed
FAILURE: Build failed with an exception.
What I've tried so far:
Went back and forth between the build.gradle and build.gradle.kts.
Added the Kotlin runtime to the jar kotlinOptions.includeRuntime = true.
Changed package level functions to functions in an object.
What I found weird:
An out directory is created in addition to the usual Gradle build directory.
Some classes/objects are compiled to class files with names ending in Kt. I've not found any rhyme or reason for this, but I'm still new to Kotlin, so I may be missing something.
Your tests (or the actual tested classes) does something strange: They delete somehow the content of the build folder which contains the test-classes.
To see this, try the following:
./gradlew clean testClasses
find build # You get a full list of all main and test classes
./gradlew clean testClasses test
find build # You get a very limited list of resources in the build-folder (must be somehow modified by your code)
If you deactivate all your tests and just add the following (just for testing purpose) in there:
import io.kotlintest.matchers.*
import io.kotlintest.specs.*
class MyTests : StringSpec() {
init {
"length should return size of string" {
"hello".length shouldBe 5
}
}
}
If you again gradle-test it,
./gradlew clean testClasses test
find build # all resources again available
Check your tests for the problem.
I started reading the gradle user guide and tried to reproduce what is done there.
So i created a file "build.gradle" and put it in here:
"c:\development\build.gradle".
That file includes the following text:
task compile << {
println 'compiling source'
}
task compileTest(dependsOn: compile) << {
println 'compiling unit tests'
}
task test(dependsOn: [compile, compileTest]) << {
println 'running unit tests'
}
task dist(dependsOn: [compile, test]) << {
println 'building the distribution'
}
Now I opened a Windows command windows and typed in this:
gradle -b C:\development\build.gradle dist test
This is what I got:
FAILURE: Build failed with an exception.
Where: Build file 'C:\development\build.gradle' line: 1
What went wrong: A problem occurred evaluating root project 'development'.
Could not find property 'compile' on root project 'development'.
Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
After some tries I found, that the file itself was been found, but I don't know why it is not executed.
What am I doing wrong?
I found the solution by myself.
Make sure, that your build file has the same encoding as your operating system.
In my case I created a UTF-8 file, but should have been an ISO-file.
After changing to the correct encoding, everything works fine.