Can't add artifacts to Custom Configuration


(Chris Hampton) #1

I’m trying to create a custom configuration so I can control the artifacts that get deployed to our local repo. I have the following code:

       File artifactFile = new File(fileName)

        def customConfig = project.configurations.customConfig

        project.artifacts {
            customConfig artifactFile
        }

This works if I add the artifact to an existing configuration like “archives”. However in this case it causes an exception: “Could not find method call() for arguments…”. So how would you add artifacts to your custom configuration?


(Chris Doré) #2

Just use the configuration name directly without creating an intermediate variable, something like:

configurations {
    customConf
}
artifacts {
    customConf ...
}

(Chris Hampton) #3

This got me a bit closer and I finely found a solution. I ended up with something like this:

project.configurations.maybeCreate('deployableArtifacts')
project.configurations.deployableArtifacts.transitive = false

File artifactFile = new File(fileName)

if ( artifactFile.exists() ) {
    project.artifacts {
        deployableArtifacts artifactFile
    }
}


project.uploadDeployableArtifacts {
    repositories.mavenDeployer {
        configuration = project.configurations.deployableArtifacts
        repository(url: releaseRepo) {
            authentication(userName: repoUser, password: repoPassword)
        }
        snapshotRepository(url: snapshotRepo) {
            authentication(userName: repoUser, password: repoPassword);
        }
    }
}