Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

custom gradle plugin causes: Cannot configure the 'publishing' extension

I have a custom gradle plugin in which custom task types and gradle configurations are added. When I apply this plugin before maven-publish it works perfectly fine. But when I add it after apply plugin: 'maven-publish', it fails with error message :

FAILURE: Build failed with an exception.

* Where:
Build file '/scratch/skgupta/git_storage/emdi/integtest/build.gradle' line: 38

* What went wrong:
A problem occurred evaluating root project 'integtest'.
> Cannot configure the 'publishing' extension after it has been accessed.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

Total time: 7.6 secs

Here is the build.gradle file.

buildscript {
    repositories {
        maven {
            url = "${artifactory_contextUrl}/repo"
        }
    }

    dependencies {
        classpath group: 'com.mycomp.proj', name: 'MyCustomPlugin', version: "${pluginVersion}", transitive: true
    }   
}
apply plugin: 'java'
apply plugin: 'maven-publish'
apply plugin: 'MyCustomPlugin'  // WHen this line is moved above maven-publish, build works fine.

// add jar name and version
jar.archiveName='lrgemaas_small_deploy_3n.jar'
group = 'com.mycom.proj.test'
version = '1.0.3'

dependencies {
    compile group: 'eaas.platform', name: 'registry-lookup-client', version: '0.1'
    compile group: 'eaas.platform', name: 'registry-client', version: '0.1'
    compile configurations.lrgConfig  // This configuration is added by MyCustomPlugin
    compile configurations.webdriver  // This configuration is added by MyCustomPlugin
}

repositories {
    maven {
        url = "${artifactory_contextUrl}/repo"
    }
}

publishing {
    publications {
        myPublicationName(MavenPublication) {
            artifactId 'lrgemaas_small_deploy_3n'
            artifact jar.archivePath
        }
    }
    repositories {
        maven {
            url = "${artifactory_contextUrl}/${artifactory_repoName}"
            credentials {
                username = "${artifactory_user}"
                password = "${artifactory_password}"
            }
        }
    }
}

// workflow for build 
defaultTasks 'clean','build','publish'

PS: I tried doing nothing in the custom plugin (i.e., simply return from apply method), but it still gives same error.

like image 595
Sundeep Gupta Avatar asked Jan 19 '15 08:01

Sundeep Gupta


1 Answers

Simply replacing:

publishing {
    publications {
      ...
  }
}

with following:

publishing.publications {
  ...
}

worked for me!

like image 88
Vinay Avatar answered Oct 16 '22 05:10

Vinay