Copy ear from repository and rename the group id and version

HI

I am trying to copy ear from repository and rename the group id and version.
Can I do Like this I am new to gradle
apply plugin: 'base’
apply plugin: ‘maven’

configurations{
egnear
}

dependencies {

egnear group: 'com.abc.xyz', name: 'sample-project', version: '3.1.1', ext: 'ear' 

}

task copyDependencies(type: Copy) {
File projectDir = new File("$buildDir")
File libs = new File(projectDir, “libs”)

into libs.getPath()
from (configurations.egnear)
rename { fileName ->
fileName.replace(‘3.1.1’, ‘’)

}
group = "com.egn.sample"
version=“1.0.0”

}

task build {
dependsOn copyDependencies
}
Thanks you