Can this be improved/made more concise? I'm new to...
# community-support
k
Can this be improved/made more concise? I'm new to tasks.register
Copy code
tasks.register('dist', Copy) {
  description = 'Copy files to dist.'
  group = BasePlugin.BUILD_GROUP
  destinationDir = 'dist' as File
  def data_archive = project.properties('data.archive')
  it.from('build/libs/some-${version}.jar') {
    into 'some.jar'
  }
  it.from('src/main/groovy/some.groovy')
  it.from(data_archive)
}
Actually, this creates a directory named some.jar. How do I copy into the destinationDir with a different name?
t
For renaming you'll want to use
rename
on the copy spec (https://docs.gradle.org/current/javadoc/org/gradle/api/file/CopySpec.html#rename-org.gradle.api.Transformer-; there's an example in https://docs.gradle.org/current/dsl/org.gradle.api.tasks.Copy.html) Btw, you'll want to reference the task that produces the JAR, rather than directly referencing the JAR filename, something like (untested, particularly as I haven't written Groovy in years):
Copy code
from(tasks.jar.archiveFile) {
  rename { 'some.jar' }
}
v
Just
tasks.jar
, unless there are multiple outputs on that task. :-)
And yes, in most cases you want
Sync
instead of
Copy
. It makes sure there are no stale files.
k
Thanks!