2

所以,我build.gradle看起来像这样,

task compile(type: Compile){
    dependsOn 'clean', 'init'

    classpath = files('bin', 
                    'lib\\foo-agent-dist-2.0.0-SNAPSHOT.jar',
                    'lib\\foo-common-2.0.0-SNAPSHOT.jar',
                    'lib\\foo-communication-api-2.0.0-SNAPSHOT.jar',
                    'lib\\spring-beans-3.1.2.RELEASE.jar',
                    'lib\\spring-context-3.1.2.RELEASE.jar',
                    'lib\\spring-web-3.1.2.RELEASE.jar',
                    'lib\\sqljdbc4-3.0.jar')
    destinationDir = file('bin')
    source = fileTree('src')
    sourceCompatibility = '1.7'
    targetCompatibility = '1.7'
}

task clean(type: Delete){
    delete 'bin'
}

task init(type: Copy){
    //TODO: Create "bin" directory if it doesn't exist
    from 'src'
    into 'bin'
    exclude '**/*.java', '**/*.bak'
    includeEmptyDirs = false
}

当我执行compile任务时,我得到以下异常

[sts] -----------------------------------------------------
[sts] Starting Gradle build for the following tasks: 
[sts]      :compile
[sts] -----------------------------------------------------
:clean
:init
:compile

FAILURE: Build failed with an exception.

* What went wrong:
A problem was found with the configuration of task ':compile'.
> No value has been specified for property 'dependencyCacheDir'.

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

* Exception is:
org.gradle.api.tasks.TaskValidationException: A problem was found with the configuration of task ':compile'.
    at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:54)
    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.tooling.internal.provider.ExecuteBuildAction.run(ExecuteBuildAction.java:31)
    at org.gradle.tooling.internal.provider.ConfiguringBuildAction.run(ConfiguringBuildAction.java:94)
    at org.gradle.launcher.daemon.protocol.Build.run(Build.java:68)
    at org.gradle.launcher.daemon.protocol.Build.run(Build.java:64)
    at org.gradle.launcher.daemon.server.exec.ExecuteBuild.doBuild(ExecuteBuild.java:45)
    at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:34)
    at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:122)
    at org.gradle.launcher.daemon.server.exec.WatchForDisconnection.execute(WatchForDisconnection.java:45)
    at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:122)
    at org.gradle.launcher.daemon.server.exec.ResetDeprecationLogger.execute(ResetDeprecationLogger.java:24)
    at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:122)
    at org.gradle.launcher.daemon.server.exec.StartStopIfBuildAndStop.execute(StartStopIfBuildAndStop.java:28)
    at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:122)
    at org.gradle.launcher.daemon.server.exec.ReturnResult.execute(ReturnResult.java:34)
    at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:122)
    at org.gradle.launcher.daemon.server.exec.ForwardClientInput$4.call(ForwardClientInput.java:116)
    at org.gradle.launcher.daemon.server.exec.ForwardClientInput$4.call(ForwardClientInput.java:114)
    at org.gradle.util.Swapper.swap(Swapper.java:38)
    at org.gradle.launcher.daemon.server.exec.ForwardClientInput.execute(ForwardClientInput.java:114)
    at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:122)
    at org.gradle.launcher.daemon.server.exec.LogToClient.doBuild(LogToClient.java:60)
    at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:34)
    at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:122)
    at org.gradle.launcher.daemon.server.exec.EstablishBuildEnvironment.doBuild(EstablishBuildEnvironment.java:61)
    at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:34)
    at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:122)
    at org.gradle.launcher.daemon.server.exec.StartBuildOrRespondWithBusy.doBuild(StartBuildOrRespondWithBusy.java:49)
    at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:34)
    at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:122)
    at org.gradle.launcher.daemon.server.exec.HandleStop.execute(HandleStop.java:34)
    at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:122)
    at org.gradle.launcher.daemon.server.exec.CatchAndForwardDaemonFailure.execute(CatchAndForwardDaemonFailure.java:32)
    at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:122)
    at org.gradle.launcher.daemon.server.exec.HandleClientDisconnectBeforeSendingCommand.execute(HandleClientDisconnectBeforeSendingCommand.java:21)
    at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:122)
    at org.gradle.launcher.daemon.server.exec.StopConnectionAfterExecution.execute(StopConnectionAfterExecution.java:27)
    at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:122)
    at org.gradle.launcher.daemon.server.exec.DefaultDaemonCommandExecuter.executeCommand(DefaultDaemonCommandExecuter.java:55)
    at org.gradle.launcher.daemon.server.Daemon$1$1.run(Daemon.java:123)
    at org.gradle.messaging.concurrent.DefaultExecutorFactory$StoppableExecutorImpl$1.run(DefaultExecutorFactory.java:66)
Caused by: org.gradle.api.InvalidUserDataException: No value has been specified for property 'dependencyCacheDir'.
    at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:46)
    ... 68 more


BUILD FAILED

为什么编译java项目需要dependencyCacheDir定义?当我定义依赖缓存目录时,它抱怨它找不到系统 Java 编译器。

什么?为什么!?什么给了,gradle?这整个经历非常令人沮丧和不必要的复杂......即将完全放弃它。

4

4 回答 4

4

如果您决定使用 Java 插件:

apply plugin : 'java'

sourceCompatibility = '1.7'
targetCompatibility = '1.7'

sourceSets {
   main {
      java {
         srcDirs = ['src']
      }
   }
}

buildDir = 'bin'

repositories {
    flatDir dirs: 'lib'
}

dependencies {
    compile ':foo-agent-dist:2.0.0-SNAPSHOT',
            ':foo-common:2.0.0-SNAPSHOT',
            ':foo-communication-api:2.0.0-SNAPSHOT',
            ':spring-beans:3.1.2.RELEASE',
            ':spring-context:3.1.2.RELEASE',
            ':spring-web:3.1.2.RELEASE',
            ':sqljdbc4:3.0'
}
于 2012-09-08T11:38:09.313 回答
3

使用JavaCompile任务类型可能会更好。

于 2013-07-19T23:53:55.170 回答
2

你为什么不使用Java插件?手动配置所有内容将需要更多努力。

如果您需要有关“系统 java 编译器”错误的帮助,请发布错误消息和堆栈跟踪。

于 2012-09-06T17:31:22.413 回答
2

这对我有用,只需对您的代码进行必要的更改,以此为例

apply plugin: 'java'

configurations {
     querydslapt
}

sourceSets {
     target
}

sourceSets.target.java.srcDirs = ['src/main/target']


dependencies {
    compile ...libraries....

        querydslapt 'com.mysema.querydsl:querydsl-apt:2.7.1'

    testCompile project(':fastappoint-test')
}

task generateQueryDSL(type: Compile, group: 'build', description: 'Generates the QueryDSL query types') {
         source = sourceSets.main.java
         classpath = configurations.compile + configurations.querydslapt
         options.compilerArgs = [
                "-proc:only",
                "-processor", "com.mysema.query.apt.jpa.JPAAnnotationProcessor"
         ]
         destinationDir = sourceSets.target.java.srcDirs.iterator().next()
         dependencyCacheDir = new File(destinationDir, "dependencyCacheDir")
}
compileJava.dependsOn generateQueryDSL
于 2013-09-29T18:52:28.047 回答