Reputation: 109
I am trying to download the artifact from nexus to my local directory using gradle task.I have to pass username/password in my gradle task to downlaod the artifact.Below is my Gradle Task
task downloadFile(type: MyDownload) {
sourceUrl = 'http://localhost:8081/xxx/xxx/xxx'
target = new File('E:/bookstore/', 'build.zip')
}
class MyDownload extends DefaultTask {
@Input
String sourceUrl
@OutputFile
File target
@TaskAction
void download() {
ant.get(src: sourceUrl, dest: target)
}
}
I am able to access with this task when i remove authorization in nexus but i need to enable authorization in nexus and pass the credentials through Gradle task
Upvotes: 1
Views: 1062
Reputation: 43148
There are many ways to do this, but my favourite is doing it through special environment variables which can be read as project properties.
ORG_GRADLE_PROJECT_nexus_user=foo
ORG_GRADLE_PROJECT_nexus_password=bar
Inside your task, just look for the project properties nexus_user
and nexus_password
:
@TaskAction
void download() {
def user = project.findProperty('nexus_user') ?: ''
def pass = project.findProperty('nexus_password') ?: ''
...
}
See also Pass env variables to gradle.properties
Upvotes: 2