I have this Gradle script as 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
}
This is the rough output:
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
This runs on a Windows Server 2012 R2 machine. I checked and there is a .war file in the defined source directory.
I can't figure out why it doesn't copy over the testApp.war file. I mean, the Source Directory are defined just fine by the other task, but why can't the copyWar task find these files?
Result of removing the << and running with the --info flag:
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.
also, the source and target variables from my Gradle.properties:
source=E\:/environments/GRADLE_TEST/TEST/TESTDEPLOY/source/72
target=E\:/environments/GRADLE_TEST/TEST/TESTDEPLOY/target
I'm completely new to Gradle, so I'm not sure what this all means.
Your error is, that the Copy
task has a property called source
.
You give the toString()
representation of this property (which is file tree
) to the from
method.
There of course no WAR
files are found and thus the copy task has nothing to do.
Either rename your source
property to something different, or use project.source
to explicitly reference the source
property of the project instead of the one from the task.
Besides that into "${target}"
is identical to into target
but is more performant. source
and target
are already strings, but you use them as placeholders which means the placeholder needs to be evaluated first which doesn't make too much sense.
Consider this gradle.properties
:
srcDir=./dist
targetDir=./target
You can replace dist
and target
with your desired folders. Using srcDir
means that we won't collide with properties of the Copy
task.
Then, this build.gradle
:
task copyWar(type: Copy) {
from srcDir
into targetDir
include '*.war'
}
should work (it does for me).
Check very carefully that you do not have directory or file names misspelled. Gradle doesn't tell you what it didn't recognize, it just says
Task :xxx NO-SOURCE
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With