Gradle war copytask not executing

**I need ***.properties to be copied to the properties DIR and exclude Environment DIR based on the params passed from Jenkins. Below is the build.gradle file and it’s not copying the properties file.

war {
println (‘here is my variable …’ + System.getProperty(‘Env’))
println (check: ‘properties/Environment/’ + System.getenv(‘Env’) + ‘/’)
task Copy(type: Copy){
from(‘properties/Environment/’ + System.getProperty(‘Env’) + ‘/’)
include(’*.properties’)
into(‘properties’)
}
exclude “properties/Environment”
manifest {
from ‘WebContent/META-INF/MANIFEST.MF’
}
}

There is no such thing as a war copy task. The code shown creates a new Copy task named Copy that would copy files between folders, not into the war. The war and Copy task are two different, unrelated tasks in the project. Even though you can’t create a task on the war task, this syntax doesn’t cause an error because it automatically delegates to the project and creates another task.

Your overall project structure isn’t clear, but you definitely have some inconsistencies on whether or not you’re including WebContent in your paths. You likely want to configure a CopySpec in the war task, and not a Copy task at all.

Although there are multiple ways to express this, using your provided code, file structure, and ignoring the other folders in WebContent that you don’t mention or show code to include, your war task configuration could look something like this:

war {
    into('properties') {
        from('WebContent/properties') { exclude 'Environment' }
        from('WebContent/properties/Environment/' + System.getProperty('Env'))
    }

    manifest {
        from 'WebContent/META-INF/MANIFEST.MF'
    }
}