Error : compileJava -> java.lang.NullPointerException (no error message)


(Marc-andre Paris-Cloutier) #1

Hello, I just installed Gradle and I’m trying to understand it but I encounter a problem when trying to build a project with the plugin ‘java’.

Just to rule out somes things, I was able to :

1- Install Gradle and run the following script

task hello {

doLast {

println ‘Hello world!’

} }

2- I could compile my Java class using javac and run it using java in the command prompt. Here is the file

public class Hello {

public String execute(){

return “Hello world!”;

}

public static void main(String [] args){

Hello hello = new Hello();

System.out.println(hello.execute());

}

}

3- The file is located in the source folder : src/main/java 4- My build.gradle file look like that : apply plugin: ‘java’

5- I use windows 7 (if it’s important)

6- If I run the command, gradle build on a folder that doesn’t exist (for example src/main/java doesn’t exist), everything work. Here is the result :

C:\Users\Denis\Documents\Temp>gradle build :compileJava UP-TO-DATE :processResources UP-TO-DATE :classes UP-TO-DATE :jar :assemble :compileTestJava UP-TO-DATE :processTestResources UP-TO-DATE :testClasses UP-TO-DATE :test :check :build

BUILD SUCCESSFUL

7- I have no idea what to do now. Help appreciated

So now here is what I get when I run the command gradle build --stacktrace on an existing folder. In this case the folder where my Hello.java file is located. (src/main/java)

C:\Users\Denis\Documents\Temp>gradle build --stacktrace :compileJava

FAILURE: Build failed with an exception.

  • What went wrong: Execution failed for task ‘:compileJava’. > java.lang.NullPointerException (no error message)

  • Try: Run with --info or --debug option to get more log output.

  • Exception is: org.gradle.api.tasks.TaskExecutionException: Execution failed for task ‘:compile Java’.

at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.ex ecuteActions(ExecuteActionsTaskExecuter.java:68)

at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.ex ecute(ExecuteActionsTaskExecuter.java:46)

at org.gradle.api.internal.tasks.execution.PostExecutionAnalysisTaskExec uter.execute(PostExecutionAnalysisTaskExecuter.java:34)

at org.gradle.api.internal.changedetection.CacheLockHandlingTaskExecuter $1.run(CacheLockHandlingTaskExecuter.java:34)

at org.gradle.cache.internal.DefaultCacheAccess$2.create(DefaultCacheAcc ess.java:200)

at org.gradle.cache.internal.DefaultCacheAccess.longRunningOperation(Def aultCacheAccess.java:172)

at org.gradle.cache.internal.DefaultCacheAccess.longRunningOperation(Def aultCacheAccess.java:198)

at org.gradle.cache.internal.DefaultPersistentDirectoryStore.longRunning Operation(DefaultPersistentDirectoryStore.java:111)

at org.gradle.api.internal.changedetection.DefaultTaskArtifactStateCache Access.longRunningOperation(DefaultTaskArtifactStateCacheAccess.java:83)

at org.gradle.api.internal.changedetection.CacheLockHandlingTaskExecuter .execute(CacheLockHandlingTaskExecuter.java:32)

at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.exec ute(SkipUpToDateTaskExecuter.java:55)

at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execut e(ValidatingTaskExecuter.java:57)

at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecu ter.execute(SkipEmptySourceFilesTaskExecuter.java:41)

at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter .execute(SkipTaskWithNoActionsExecuter.java:51)

at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execut e(SkipOnlyIfTaskExecuter.java:52)

at org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter .execute(ExecuteAtMostOnceTaskExecuter.java:42)

at org.gradle.api.internal.AbstractTask.executeWithoutThrowingTaskFailur e(AbstractTask.java:247)

at org.gradle.execution.DefaultTaskGraphExecuter.executeTask(DefaultTask GraphExecuter.java:192)

at org.gradle.execution.DefaultTaskGraphExecuter.doExecute(DefaultTaskGr aphExecuter.java:177)

at org.gradle.execution.DefaultTaskGraphExecuter.execute(DefaultTaskGrap hExecuter.java:83)

at org.gradle.execution.SelectedTaskExecutionAction.execute(SelectedTask ExecutionAction.java:36)

at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecute r.java:61)

at org.gradle.execution.DefaultBuildExecuter.access$200(DefaultBuildExec uter.java:23)

at org.gradle.execution.DefaultBuildExecuter$2.proceed(DefaultBuildExecu ter.java:67)

at org.gradle.api.internal.changedetection.TaskCacheLockHandlingBuildExe cuter$1.run(TaskCacheLockHandlingBuildExecuter.java:31)

at org.gradle.cache.internal.DefaultCacheAccess$1.create(DefaultCacheAcc ess.java:111)

at org.gradle.cache.internal.DefaultCacheAccess.useCache(DefaultCacheAcc ess.java:126)

at org.gradle.cache.internal.DefaultCacheAccess.useCache(DefaultCacheAcc ess.java:109)

at org.gradle.cache.internal.DefaultPersistentDirectoryStore.useCache(De faultPersistentDirectoryStore.java:103)

at org.gradle.api.internal.changedetection.DefaultTaskArtifactStateCache Access.useCache(DefaultTaskArtifactStateCacheAccess.java:79)

at org.gradle.api.internal.changedetection.TaskCacheLockHandlingBuildExe cuter.execute(TaskCacheLockHandlingBuildExecuter.java:29)

at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecute r.java:61)

at org.gradle.execution.DefaultBuildExecuter.access$200(DefaultBuildExec uter.java:23)

at org.gradle.execution.DefaultBuildExecuter$2.proceed(DefaultBuildExecu ter.java:67)

at org.gradle.execution.DryRunBuildExecutionAction.execute(DryRunBuildEx ecutionAction.java:32)

at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecute r.java:61)

at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecute r.java:54)

at org.gradle.initialization.DefaultGradleLauncher.doBuildStages(Default GradleLauncher.java:155)

at org.gradle.initialization.DefaultGradleLauncher.doBuild(DefaultGradle Launcher.java:110)

at org.gradle.initialization.DefaultGradleLauncher.run(DefaultGradleLaun cher.java:78)

at org.gradle.launcher.cli.RunBuildAction.execute(RunBuildAction.java:42 )

at org.gradle.launcher.cli.RunBuildAction.execute(RunBuildAction.java:28 )

at org.gradle.launcher.exec.ExceptionReportingAction.execute(ExceptionRe portingAction.java:32)

at org.gradle.launcher.exec.ExceptionReportingAction.execute(ExceptionRe portingAction.java:21)

at org.gradle.launcher.cli.CommandLineActionFactory$WithLoggingAction.ex ecute(CommandLineActionFactory.java:302)

at org.gradle.launcher.cli.CommandLineActionFactory$WithLoggingAction.ex ecute(CommandLineActionFactory.java:286)

at org.gradle.launcher.Main.doAction(Main.java:48)

at org.gradle.launcher.exec.EntryPoint$1.execute(EntryPoint.java:53)

at org.gradle.launcher.exec.EntryPoint$1.execute(EntryPoint.java:51)

at org.gradle.launcher.exec.Execution.execute(Execution.java:28)

at org.gradle.launcher.exec.EntryPoint.run(EntryPoint.java:39)

at org.gradle.launcher.Main.main(Main.java:39)

at org.gradle.launcher.ProcessBootstrap.runNoExit(ProcessBootstrap.java: 51)

at org.gradle.launcher.ProcessBootstrap.run(ProcessBootstrap.java:33)

at org.gradle.launcher.GradleMain.main(GradleMain.java:24) Caused by: java.lang.NullPointerException

at org.gradle.api.internal.tasks.compile.jdk6.Jdk6JavaCompiler.createCom pileTask(Jdk6JavaCompiler.java:52)

at org.gradle.api.internal.tasks.compile.jdk6.Jdk6JavaCompiler.execute(J dk6JavaCompiler.java:39)

at org.gradle.api.internal.tasks.compile.jdk6.Jdk6JavaCompiler.execute(J dk6JavaCompiler.java:33)

at org.gradle.api.internal.tasks.compile.NormalizingJavaCompiler.delegat eAndHandleErrors(NormalizingJavaCompiler.java:95)

at org.gradle.api.internal.tasks.compile.NormalizingJavaCompiler.execute (NormalizingJavaCompiler.java:48)

at org.gradle.api.internal.tasks.compile.NormalizingJavaCompiler.execute (NormalizingJavaCompiler.java:34)

at org.gradle.api.internal.tasks.compile.DelegatingJavaCompiler.execute( DelegatingJavaCompiler.java:29)

at org.gradle.api.internal.tasks.compile.DelegatingJavaCompiler.execute( DelegatingJavaCompiler.java:20)

at org.gradle.api.internal.tasks.compile.IncrementalJavaCompilerSupport. execute(IncrementalJavaCompilerSupport.java:33)

at org.gradle.api.internal.tasks.compile.IncrementalJavaCompilerSupport. execute(IncrementalJavaCompilerSupport.java:23)

at org.gradle.api.tasks.compile.Compile.compile(Compile.java:60)

at org.gradle.api.internal.BeanDynamicObject$MetaClassAdapter.invokeMeth od(BeanDynamicObject.java:196)

at org.gradle.api.internal.BeanDynamicObject.invokeMethod(BeanDynamicObj ect.java:102)

at org.gradle.api.internal.CompositeDynamicObject.invokeMethod(Composite DynamicObject.java:99)

at org.gradle.api.tasks.compile.Compile_Decorated.invokeMethod(Unknown S ource)

at org.gradle.util.ReflectionUtil.invoke(ReflectionUtil.groovy:23)

at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskF actory$4.execute(AnnotationProcessingTaskFactory.java:150)

at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskF actory$4.execute(AnnotationProcessingTaskFactory.java:145)

at org.gradle.api.internal.AbstractTask$TaskActionWrapper.execute(Abstra ctTask.java:477)

at org.gradle.api.internal.AbstractTask$TaskActionWrapper.execute(Abstra ctTask.java:466)

at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.ex ecuteActions(ExecuteActionsTaskExecuter.java:60)

… 54 more

BUILD FAILED

Total time: 2.948 secs

Thx for help!


(René Groeschke) #2

Not sure if I understand you correctly. You have one source file in src/main/java and as soon as you run “gradle build” from the root project you get the Nullpointer exception? Unfortunately I cannot yet reproduce your bug.

regards, René


(Adam Murdoch) #3

Can you post the output of ‘gradle -v’, please? Also, what is your JAVA_HOME environment variable set to, if anything?


(Marc-andre Paris-Cloutier) #4

Thx for reply.

Here is the output of gradle -v

C:\Users\Denis\Documents\Temp>gradle -v

------------------------------------------------------------ Gradle 1.0-milestone-9 ------------------------------------------------------------

Gradle build time: mardi 13 mars 2012 16 h 10 UTC Groovy: 1.8.6 Ant: Apache Ant™ version 1.8.2 compiled on December 20 2010 Ivy: 2.2.0 JVM: 1.6.0_23 (Sun Microsystems Inc. 19.0-b09) OS: Windows 7 6.1 amd64

C:\Users\Denis\Documents\Temp>

I didn’t had a variable JAVA_HOME but the path for the JDK was in my PATH variable.

I tried creating a variable JAVA_HOME with the path to the JDK but it didn’t seems to change anything, still get the same error.


(Marc-andre Paris-Cloutier) #5

@Rene Yes, I’m in a folder containaing the folder src/main/java/Hello.java. When I run the command “gradle build” it give me the NullPointerException.

I tried changing the sourceSet like it was explain in the documentation and it crash too. In fact as soon as I referenced an existing folder it crash but if I referenced a folder that doesn’t exist it print that the build is a success with the usual message :

C:\Users\Denis\Documents\Temp>gradle build

:compileJava UP-TO-DATE

:processResources UP-TO-DATE

:classes UP-TO-DATE

:jar

:assemble

:compileTestJava UP-TO-DATE

:processTestResources UP-TO-DATE

:testClasses UP-TO-DATE

:test

:check

:build

BUILD SUCCESSFUL


(René Groeschke) #6

I was able to reproduce this error by:

  1. point the JAVA_HOME to a JRE installation instead of a JDK 2. remove the JAVA_HOME variable at all.

Can you please double check that your JAVA_HOME variable points to a valid JDK installation (by calling “set JAVA_HOME” directly before running the gradle command)? Nevertheless, Gradle should be more gracefully here and not fail with a NullpointerException.

regards, René


(Marc-andre Paris-Cloutier) #7

Thx for the help!!

It work. This morning when I restart my comp it gave me an error about an invalid JAVA_HOME variable instead of the NullPointerException.

Then instead of putting the bin folder of the JDK as my path I just put the path to the JDK and now it works :slight_smile:

Any way to mark this issue as fixed?


(René Groeschke) #8

Good to hear its now working for you.

As mentioned before, gradle should handle this cases more gracefully. We’ve raised a bug in JIRA for this: http://issues.gradle.org/browse/GRADLE-2187

regards, René