gpt4 book ai didi

Gradle Copy 任务说没有来源

转载 作者:行者123 更新时间:2023-12-04 04:25:27 24 4
gpt4 key购买 nike

我有这个 Gradle 脚本作为 deploy.gradle(Gradle 4.3.1):

defaultTasks 'echoProp'
import org.apache.tools.ant.filters.ReplaceTokens

task copyWar(type: Copy) {
from "${source}"
into "${target}"
include '*.war'
}

task echoProp(dependsOn: copyWar) << {
println "source dir: ${source}"
println "target dir: ${target}"
println "source = ${project.property('source')}"
def currentJvm = org.gradle.internal.jvm.Jvm.current()
println currentJvm
}

这是粗略的输出:
                                        The Task.leftShift(Closure) method has been deprecated and is scheduled to be removed in Gradle 5.0. Please use Task.doLast(Action) instead.
at deploy_13e4yjnom30svmprt2wccq4te.run(E:\environments\GRADLE_TEST\TEST\TESTDEPLOY\source\71\deploy.gradle:10)
(Run with --stacktrace to get the full stack trace of this deprecation warning.)
:copyWar NO-SOURCE
:echoProp
source dir: E:/environments/GRADLE_TEST/TEST/TESTDEPLOY/source/71
target dir: E:/environments/GRADLE_TEST/TEST/TESTDEPLOY/target
source = E:/environments/GRADLE_TEST/TEST/TESTDEPLOY/source/71
1.8.0_31 (Oracle Corporation 25.31-b07)

BUILD SUCCESSFUL in 1s
1 actionable task: 1 executed

这在 Windows Server 2012 R2 机器上运行。我检查并在定义的源目录中有一个 .war 文件。

我不知道为什么它不复制 testApp.war 文件。我的意思是,源目录由其他任务定义得很好,但是为什么 copyWar 任务找不到这些文件?

删除 << 并使用 --info 标志运行的结果:
Initialized native services in: C:\Windows\System32\config\systemprofile\.gradle\native
The client will now receive all logging from the daemon (pid: 5580). The daemon log file: C:\Windows\System32\config\systemprofile\.gradle\daemon\4.3.1\daemon-5580.out.log
Starting 19th build in daemon [uptime: 1 hrs 14 mins 1.715 secs, performance: 98%, no major garbage collections]
Using 2 worker leases.
Creating new cache for fileHashes, path E:\environments\GRADLE_TEST\TEST\TESTDEPLOY\source\72\.gradle\4.3.1\fileHashes\fileHashes.bin, access org.gradle.cache.internal.DefaultCacheAccess@6e59e113
Creating new cache for plugin-use-metadata, path C:\Windows\System32\config\systemprofile\.gradle\caches\4.3.1\plugin-resolution\plugin-use-metadata.bin, access org.gradle.cache.internal.DefaultCacheAccess@4092835c
Creating new cache for client-status, path C:\Windows\System32\config\systemprofile\.gradle\caches\4.3.1\plugin-resolution\client-status.bin, access org.gradle.cache.internal.DefaultCacheAccess@4092835c
Starting Build
Settings evaluated using settings file.
Projects loaded. Root project using build file 'E:\environments\GRADLE_TEST\TEST\TESTDEPLOY\source\72\deploy.gradle'.
Included projects: [root project '72']
Evaluating root project '72' using build file 'E:\environments\GRADLE_TEST\TEST\TESTDEPLOY\source\72\deploy.gradle'.
Compiling build file 'E:\environments\GRADLE_TEST\TEST\TESTDEPLOY\source\72\deploy.gradle' using SubsetScriptTransformer.
Compiling build file 'E:\environments\GRADLE_TEST\TEST\TESTDEPLOY\source\72\deploy.gradle' using BuildScriptTransformer.
source dir: file tree
target dir: E:/environments/GRADLE_TEST/TEST/TESTDEPLOY/target
source dir: E:/environments/GRADLE_TEST/TEST/TESTDEPLOY/source/72
target dir: E:/environments/GRADLE_TEST/TEST/TESTDEPLOY/target
source = E:/environments/GRADLE_TEST/TEST/TESTDEPLOY/source/72
1.8.0_31 (Oracle Corporation 25.31-b07)
All projects evaluated.
No tasks specified. Using project default tasks 'echoProp'
Selected primary task 'echoProp' from project :
Tasks to be executed: [task ':copyWar', task ':echoProp']
Creating new cache for resourceHashesCache, path E:\environments\GRADLE_TEST\TEST\TESTDEPLOY\source\72\.gradle\4.3.1\fileHashes\resourceHashesCache.bin, access org.gradle.cache.internal.DefaultCacheAccess@6e59e113
Creating new cache for taskHistory, path E:\environments\GRADLE_TEST\TEST\TESTDEPLOY\source\72\.gradle\4.3.1\taskHistory\taskHistory.bin, access org.gradle.cache.internal.DefaultCacheAccess@1e64a7a6
Creating new cache for outputFiles, path E:\environments\GRADLE_TEST\TEST\TESTDEPLOY\source\72\.gradle\buildOutputCleanup\outputFiles.bin, access org.gradle.cache.internal.DefaultCacheAccess@4faa606d
:copyWar (Thread[Daemon worker Thread 15,5,main]) started.
:copyWar
Putting task artifact state for task ':copyWar' into context took 0.0 secs.
Skipping task ':copyWar' as it has no source files and no previous output files.
:copyWar NO-SOURCE
:copyWar (Thread[Daemon worker Thread 15,5,main]) completed. Took 0.002 secs.
:echoProp (Thread[Daemon worker Thread 15,5,main]) started.
:echoProp
Skipping task ':echoProp' as it has no actions.
:echoProp UP-TO-DATE
:echoProp (Thread[Daemon worker Thread 15,5,main]) completed. Took 0.004 secs.

另外,我的 Gradle.properties 中的源变量和目标变量:
source=E\:/environments/GRADLE_TEST/TEST/TESTDEPLOY/source/72
target=E\:/environments/GRADLE_TEST/TEST/TESTDEPLOY/target

我对 Gradle 完全陌生,所以我不确定这一切意味着什么。

最佳答案

您的错误是,Copy任务有一个名为 source 的属性.
你给 toString()将此属性(即 file tree )表示为 from方法。
当然没有WAR文件被找到,因此复制任务无关。
重命名您的 source属性到不同的东西,或使用project.source明确引用 source项目的属性,而不是任务的属性。

除此之外into "${target}"等同于 into target但性能更高。 sourcetarget已经是字符串,但是您将它们用作占位符,这意味着需要首先评估占位符,这没有太大意义。

关于Gradle Copy 任务说没有来源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47637123/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com