'testCompile' fails when compiling Spock specifications with 'sourceCompatibility' and 'targetCompatibility' properties set to '1.4'

Hi,

I have a problem compiling the spock specifications of my project when using a gradle version higher than ‘Gradle 1.0-milestone-9’. I also tried this with different JVM versions but it fails when I use ‘Gradle 1.0-rc-1’, ‘Gradle 1.0-rc-2’ and ‘Gradle 1.0-rc-3’. If I change the sourceCompatibility = ‘1.4’ and targetCompatibility = ‘1.4’ properties to ‘1.5’ it works.

Running the command ‘gradle clean testClasses --full-stacktrace’ returns the following output:

:clean > :compileJavawarning: [options] bootstrap class path not set in conjunction with -source 1.4 > 1 warning >

:compileGroovy UP-TO-DATE > :processResources > :classes > :compileTestJava UP-TO-DATE > :compileTestGroovystartup failed: > C:\dev\ws\FusionAnalytics\Licensing\fusionanalytics-keygen\src\test\groovy\com\intergral\fusionanalytics\keygen\KeyGenSpecification.groovy: > 13: Annotations are not supported in the current runtime. Please make sure you are running on a JVM >= 1.5 > @ line 13, column 1. >

class KeyGenSpecification extends Specification { >

^ >

C:\dev\ws\FusionAnalytics\Licensing\fusionanalytics-keygen\src\test\groovy\com\intergral\fusionanalytics\keygen\KeyGenSpecification.groovy: > 15: Annotations are not supported in the current runtime. Please make sure you are running on a JVM >= 1.5 > @ line 15, column 5. >

def baseDir = new File(‘target/classes/test/’) >

^ >

C:\dev\ws\FusionAnalytics\Licensing\fusionanalytics-keygen\src\test\groovy\com\intergral\fusionanalytics\keygen\KeyGenSpecification.groovy: > 16: Annotations are not supported in the current runtime. Please make sure you are running on a JVM >= 1.5 > @ line 16, column 5. >

def storeFile = new File(baseDir, ‘license.store’) >

^ >

C:\dev\ws\FusionAnalytics\Licensing\fusionanalytics-keygen\src\test\groovy\com\intergral\fusionanalytics\keygen\KeyGenSpecification.groovy: > 17: Annotations are not supported in the current runtime. Please make sure you are running on a JVM >= 1.5 > @ line 17, column 5. >

def licMgr = new LicenseManager(new FusionAnalyticsLicenseParam()); >

^ >

C:\dev\ws\FusionAnalytics\Licensing\fusionanalytics-keygen\src\test\groovy\com\intergral\fusionanalytics\keygen\KeyGenSpecification.groovy: > 20: Annotations are not supported in the current runtime. Please make sure you are running on a JVM >= 1.5 > @ line 20, column 5. >

def ‘A license for each product can be created’() { >

^ >

C:\dev\ws\FusionAnalytics\Licensing\fusionanalytics-keygen\src\test\groovy\com\intergral\fusionanalytics\keygen\KeyGenSpecification.groovy: > 73: Annotations are not supported in the current runtime. Please make sure you are running on a JVM >= 1.5 > @ line 73, column 5. >

def ‘Create a generic trial license’() { >

^ >

C:\dev\ws\FusionAnalytics\Licensing\fusionanalytics-keygen\src\test\groovy\com\intergral\fusionanalytics\keygen\ProductSpecification.groovy: > 15: Annotations are not supported in the current runtime. Please make sure you are running on a JVM >= 1.5 > @ line 15, column 1. >

class ProductSpecification extends Specification { >

^ >

C:\dev\ws\FusionAnalytics\Licensing\fusionanalytics-keygen\src\test\groovy\com\intergral\fusionanalytics\keygen\ProductSpecification.groovy: > 17: Annotations are not supported in the current runtime. Please make sure you are running on a JVM >= 1.5 > @ line 17, column 5. >

def ‘The Product Database does handle a Trial license correctly’() { >

^ >

C:\dev\ws\FusionAnalytics\Licensing\fusionanalytics-keygen\src\test\groovy\com\intergral\fusionanalytics\keygen\ProductSpecification.groovy: > 33: Annotations are not supported in the current runtime. Please make sure you are running on a JVM >= 1.5 > @ line 33, column 5. >

def ‘The Product Database does handle product 300432817 correctly’() { >

^ >

C:\dev\ws\FusionAnalytics\Licensing\fusionanalytics-keygen\src\test\groovy\com\intergral\fusionanalytics\keygen\ProductSpecification.groovy: > 47: Annotations are not supported in the current runtime. Please make sure you are running on a JVM >= 1.5 > @ line 47, column 5. >

def ‘The Product Database does handle product 300469513 correctly’() { >

^ >

C:\dev\ws\FusionAnalytics\Licensing\fusionanalytics-keygen\src\test\groovy\com\intergral\fusionanalytics\keygen\ProductSpecification.groovy: > 62: Annotations are not supported in the current runtime. Please make sure you are running on a JVM >= 1.5 > @ line 62, column 5. >

def ‘The Product database does handle errors correctly’() { >

^ >

11 errors >

FAILURE: Build failed with an exception. >

  • What went wrong: > Execution failed for task ‘:compileTestGroovy’. > > Compilation failed; see the compiler error output for details. >
  • Try: > Run with --info or --debug option to get more log output. >
  • Exception is: > org.gradle.api.tasks.TaskExecutionException: Execution failed for task ‘:compileTestGroovy’. > at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:68) > at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:46) > at org.gradle.api.internal.tasks.execution.PostExecutionAnalysisTaskExecuter.execute(PostExecutionAnalysisTaskExecuter.java:34) > at org.gradle.api.internal.changedetection.CacheLockHandlingTaskExecuter$1.run(CacheLockHandlingTaskExecuter.java:34) > at org.gradle.cache.internal.DefaultCacheAccess$2.create(DefaultCacheAccess.java:200) > at org.gradle.cache.internal.DefaultCacheAccess.longRunningOperation(DefaultCacheAccess.java:172) > at org.gradle.cache.internal.DefaultCacheAccess.longRunningOperation(DefaultCacheAccess.java:198) > at org.gradle.cache.internal.DefaultPersistentDirectoryStore.longRunningOperation(DefaultPersistentDirectoryStore.java:111) > at > org.gradle.api.internal.changedetection.DefaultTaskArtifactStateCacheAccess.longRunningOperation(DefaultTaskArtifactStateCacheAccess.java:83) > at org.gradle.api.internal.changedetection.CacheLockHandlingTaskExecuter.execute(CacheLockHandlingTaskExecuter.java:32) > at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.java:55) > at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:57) > at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:41) > at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:51) > at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:52) > at org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter.execute(ExecuteAtMostOnceTaskExecuter.java:42) > at org.gradle.api.internal.AbstractTask.executeWithoutThrowingTaskFailure(AbstractTask.java:247) > at org.gradle.execution.DefaultTaskGraphExecuter.executeTask(DefaultTaskGraphExecuter.java:192) > at org.gradle.execution.DefaultTaskGraphExecuter.doExecute(DefaultTaskGraphExecuter.java:177) > at org.gradle.execution.DefaultTaskGraphExecuter.execute(DefaultTaskGraphExecuter.java:83) > at org.gradle.execution.SelectedTaskExecutionAction.execute(SelectedTaskExecutionAction.java:36) > at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:61) > at org.gradle.execution.DefaultBuildExecuter.access$200(DefaultBuildExecuter.java:23) > at org.gradle.execution.DefaultBuildExecuter$2.proceed(DefaultBuildExecuter.java:67) > at org.gradle.api.internal.changedetection.TaskCacheLockHandlingBuildExecuter$1.run(TaskCacheLockHandlingBuildExecuter.java:31) > at org.gradle.cache.internal.DefaultCacheAccess$1.create(DefaultCacheAccess.java:111) > at org.gradle.cache.internal.DefaultCacheAccess.useCache(DefaultCacheAccess.java:126) > at org.gradle.cache.internal.DefaultCacheAccess.useCache(DefaultCacheAccess.java:109) > at org.gradle.cache.internal.DefaultPersistentDirectoryStore.useCache(DefaultPersistentDirectoryStore.java:103) > at org.gradle.api.internal.changedetection.DefaultTaskArtifactStateCacheAccess.useCache(DefaultTaskArtifactStateCacheAccess.java:79) > at org.gradle.api.internal.changedetection.TaskCacheLockHandlingBuildExecuter.execute(TaskCacheLockHandlingBuildExecuter.java:29) > at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:61) > at org.gradle.execution.DefaultBuildExecuter.access$200(DefaultBuildExecuter.java:23) > at org.gradle.execution.DefaultBuildExecuter$2.proceed(DefaultBuildExecuter.java:67) > at org.gradle.execution.DryRunBuildExecutionAction.execute(DryRunBuildExecutionAction.java:32) > at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:61) > at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:54) > at org.gradle.initialization.DefaultGradleLauncher.doBuildStages(DefaultGradleLauncher.java:155) > at org.gradle.initialization.DefaultGradleLauncher.doBuild(DefaultGradleLauncher.java:110) > at org.gradle.initialization.DefaultGradleLauncher.run(DefaultGradleLauncher.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.cli.CommandLineActionFactory$ParseAndBuildAction.execute(CommandLineActionFactory.java:201) > at org.gradle.launcher.cli.CommandLineActionFactory$ParseAndBuildAction.execute(CommandLineActionFactory.java:174) > at org.gradle.launcher.cli.CommandLineActionFactory$WithLogging.execute(CommandLineActionFactory.java:170) > at org.gradle.launcher.cli.CommandLineActionFactory$WithLogging.execute(CommandLineActionFactory.java:139) > at org.gradle.launcher.exec.ExceptionReportingAction.execute(ExceptionReportingAction.java:31) > at org.gradle.launcher.exec.ExceptionReportingAction.execute(ExceptionReportingAction.java:20) > at org.gradle.launcher.Main.doAction(Main.java:48) > at org.gradle.launcher.exec.EntryPoint.run(EntryPoint.java:45) > at org.gradle.launcher.Main.main(Main.java:39) > at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) > at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) > at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) > at java.lang.reflect.Method.invoke(Method.java:601) > at org.gradle.launcher.ProcessBootstrap.runNoExit(ProcessBootstrap.java:50) > at org.gradle.launcher.ProcessBootstrap.run(ProcessBootstrap.java:32) > at org.gradle.launcher.GradleMain.main(GradleMain.java:24) > Caused by: org.gradle.api.internal.tasks.compile.CompilationFailedException: Compilation failed; see the compiler error output for details. > at org.gradle.api.internal.tasks.compile.ApiGroovyCompiler.execute(ApiGroovyCompiler.java:112) > at org.gradle.api.internal.tasks.compile.ApiGroovyCompiler.execute(ApiGroovyCompiler.java:39) > at org.gradle.api.internal.tasks.compile.daemon.CompilerDaemonServer.execute(CompilerDaemonServer.java:52) > at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) > at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) > at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) > at java.lang.reflect.Method.invoke(Method.java:601) > at org.gradle.messaging.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:35) > at org.gradle.messaging.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24) > at org.gradle.messaging.remote.internal.TypeCastDispatch.dispatch(TypeCastDispatch.java:30) > at org.gradle.messaging.remote.internal.WorkerProtocol.handleIncoming(WorkerProtocol.java:53) > at org.gradle.messaging.remote.internal.WorkerProtocol.handleIncoming(WorkerProtocol.java:31) > at org.gradle.messaging.remote.internal.ProtocolStack$ProtocolStage.handleIncoming(ProtocolStack.java:167) > at org.gradle.messaging.remote.internal.ProtocolStack$BottomStage.handleIncoming(ProtocolStack.java:277) > at org.gradle.messaging.remote.internal.ProtocolStack$BottomConnection$1.run(ProtocolStack.java:299) > at org.gradle.messaging.remote.internal.ProtocolStack$ExecuteRunnable.dispatch(ProtocolStack.java:120) > at org.gradle.messaging.remote.internal.ProtocolStack$ExecuteRunnable.dispatch(ProtocolStack.java:116) > at org.gradle.messaging.dispatch.AsyncDispatch.dispatchMessages(AsyncDispatch.java:132) > at org.gradle.messaging.dispatch.AsyncDispatch.access$000(AsyncDispatch.java:33) > at org.gradle.messaging.dispatch.AsyncDispatch$1.run(AsyncDispatch.java:72) > at org.gradle.messaging.concurrent.DefaultExecutorFactory$StoppableExecutorImpl$1.run(DefaultExecutorFactory.java:66) > at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110) > at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603) > at java.lang.Thread.run(Thread.java:722) >

BUILD FAILED >

Total time: 10.846 secs

The dependencies in the build file are:

dependencies {
    groovy "org.codehaus.groovy:groovy-all:1.8.6"
    compile "commons-codec:commons-codec:1.4"
    testCompile "org.spockframework:spock-core:0.6-groovy-1.8"
}

It does work with M9: > ------------------------------------------------------------ > Gradle 1.0-milestone-9 > ------------------------------------------------------------ >

Gradle build time: Dienstag, 13. März 2012 16:10 Uhr UTC > Groovy: 1.8.6 > Ant: Apache Ant™ version 1.8.2 compiled on December 20 2010 > Ivy: 2.2.0 > JVM: 1.7.0_04 (Oracle Corporation 23.0-b21) > OS: Windows 7 6.1 amd64

It does not work with later versions: > ------------------------------------------------------------ > Gradle 1.0-rc-3 > ------------------------------------------------------------ >

Gradle build time: Sonntag, 29. April 2012 23:51 Uhr UTC > Groovy: 1.8.6 > Ant: Apache Ant™ version 1.8.2 compiled on December 20 2010 > Ivy: 2.2.0 > JVM: 1.7.0_04 (Oracle Corporation 23.0-b21) > OS: Windows 7 6.1 amd64

Thanks, Bernd

Until m9, ‘targetCompatibility’ wasn’t passed on to the Groovy compiler, and the compiler would always default to 1.5. With the new Groovy compiler integration introduced in rc-1, ‘targetCompatibility’ is passed on, and you have to provide a suitable value. Spock requires 1.5 (or higher).

Conversely, the ‘sourceCompatibility’ property isn’t relevant for Groovy compilation. Note that ‘targetCompatibility’ defaults to ‘sourceCompatibility’ (because it makes sense from a Java perspective).

Hi Peter,

Thank you for the clarification and the fast reply!

Bernd