Ivy-publish custom configurations

I am attempting to publish ivy artifacts using ivy-publish with gradle 2.2.1. I am using the following technique to make use of an existing ivy config file:

The following code loads the config file and sets configurations in the project:

def _define = { x, y -> logger.debug("_define " + x + " " + y); if (!project.ext.has(x)) { project.ext.set(x, y) } }
  _define "ivyConfigurationsFile", "$System.env.HOME/.ivy2/config/ivy-configurations-1.0.xml"
  configurations {
 logger.info("Setting up repository configurations")
 def parsedXml = (new XmlParser()).parse(project.ext.ivyConfigurationsFile)
 parsedXml.value().each { conf ->
  logger.debug("Parsing " + conf.attributes())
      // Bug in plugins... exclude this
  if ("default".equals(conf.attribute("name"))) {
      def localConf = maybeCreate(conf.attribute("name"))
  if (conf.attribute("visibility") != null) {
   localConf.visible = !"private".equals(conf.attribute("visibility"))
  } else {
   localConf.visible = true
      logger.info("Adding configuration " + conf.attribute("name") + " with visibility " + localConf.visible)
     if (conf.attribute("description") != null) {
   localConf.description = conf.attribute("description")
      if (conf.attribute("extends") != null) {
   def extenders = conf.attribute("extends").split(",") as Set
   // Note - this will fail if confs out of order in file
   localConf.extendsFrom = extenders.collect({ configurations.getByName(it.trim()) })

It is called from the following. I am attempting to apply a common configuration to the ivy-publish plugin:

apply plugin: 'ivy-publish'
apply plugin: 'maven'
  apply from: "${shareDir}/gradle/ivy-configurations-1.0.gradle"
apply from: "${shareDir}/gradle/ivysettings-3.0.gradle"
  publishing {
    publications {
        ivy(IvyPublication) {
         descriptor {
          withXml {
           // Remove default configurations in lieu of our own
                        project.configurations.each { conf ->
             println " " + conf.name + " " + conf.visible + " " + conf.description
            def appendConfig = [name: conf.name, visibility: conf.isVisible()? "public" : "private", description:conf.description]
            def appendExtends = conf.extendsFrom.collect({ it.name }).join(",")
              if (appendExtends.length() > 0) {
             appendConfig["extends"] = appendExtends
                          asNode().configurations[0].appendNode('conf', appendConfig)
        from components.java
        artifacts.each( { it.conf = "master, runtime" } )
       repositories {
  add project.repositories.getByName("local")
  add project.repositories.getByName("prerelease-put")

The problem is that something appears to be overwriting my project configurations. After running the load from the ivy config file it reads compile, runtime, and master as visible (public). However, when the ivy configuration closure is hit it is reading those as being invisible and with a different description.

Here is relevant output: Adding configuration master with visibility true Adding configuration tools with visibility false Adding configuration compile-int with visibility false Adding configuration provided with visibility false Adding configuration compile with visibility true Adding configuration runtime with visibility true Adding configuration test with visibility false … Executing task ‘:generateDescriptorFileForIvyPublication’ (up-to-date check took 0.0060 secs) due to:

Task.upToDateWhen is false.

archives true Configuration for archive artifacts.

compile false Compile classpath for source set ‘main’.

compile-int false artifacts needed internally by this artifact to compile the application

default true Configuration for default artifacts.

integTestCompile false Compile classpath for source set ‘integ test’.

integTestRuntime false Runtime classpath for source set ‘integ test’.

master true the published artifact but no dependencies

provided false artifacts needed to build this artifact but are not needed at runtime; they are provided by their environment

runtime false Runtime classpath for source set ‘main’.

test false artifacts not in compile or runtime needed to build and run the tests

testCompile false Compile classpath for source set ‘test’.

testRuntime false Runtime classpath for source set ‘test’.

tools false artifacts needed to build the application, such as for custom Ant tasks

So my question is what is overriding my configurations and how can I stop that from happening? Is there a better way for me to do this? As it is the ivy plugin seems rather limited to I had to use custom xml.

It looks like the java plugin is tampering with my configurations: https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/groovy/org/gradle/api/plugins/JavaPlugin.java

Can this be prevented?

Update: I worked around this by placing my configuration setup in gradle.afterProject. I’m not too keen on plugins messing around with my configuration though. Seems to me that the plugin should only setup those values if nothing else has been setup (i.e. a default configuration).