Applying plugins in init.gradle

Hi,

I am wondering why this init script (init.gradle)

initscript {

allprojects {

buildscript {

repositories {

maven {

url ‘http://localhost:8091/artifactory/plugins-release

credentials {

username = ‘${artifactory_resolve_username}’

password = ‘${artifactory_resolve_password}’

}

}

dependencies {

classpath(group: ‘org.jfrog.buildinfo’, name: ‘build-info-extractor-gradle’, version: ‘2.0.17’)

}

}

}

apply plugin: ‘maven’

apply plugin: ‘artifactory’

} }

produces an exception (with an empty build) for “gradle tasks”:

  • What went wrong: Failed to notify action. > Plugin with id ‘artifactory’ not found.

However, if I remove the line “apply plugin: ‘artifactory’” from the init.gradle and put it into the build.gradle file, everything works.

Thanks a lot for help!

Boris

It’s effectively a bug/shortcoming (GRADLE-2407).

There’s a workaround posted @ http://forums.gradle.org/gradle/topics/how_can_you_use_an_init_script_to_specify_a_repo_dependency_for_a_plugin_jar_but_allow_version_to that gets you close to what you want.

Thanks a lot! I think the workaround will not help in my situation.

I wanted to put the parts of the artifactory related configuration into the init script to avoid having access/credentials related information in the build script (submitted to SVN). I.e. I want to have this line

username = “${artifactory_publish_username}”

in the init script, not in the build.gradle. This is only possible if I apply the plugin in init.gradle.

The reason is that this script should be executed on a CI server (teamcity) that has its own credentials. It does not know the variables (like artifactory_publish_username) defined to execute the script locally. Therefore it fails.

You have to apply the plugin in the buildscript, but you can configure it in the init script…

initscript {
   allprojects {
     buildscript {
       repositories {
         maven {
           url 'http://localhost:8091/artifactory/plu...'
           credentials {
             username = '${artifactoryresolveusername}'
             password = '${artifactoryresolvepassword}'
           }
          }
         dependencies {
           classpath(group: 'org.jfrog.buildinfo', name: 'build-info-extractor-gradle', version: '2.0.17')
         }
       }
     }
     apply plugin: 'maven'
     apply plugin: 'artifactory'
   }
       plugins.matching { it.class.name == "org.jfrog.gradle.plugin.artifactory.ArtifactoryPlugin" }.all {
    // do artifactory plugin config here, just like in buildscript
  }
}

So you can configure the plugin in the init script, but you still need to actually apply it in the buildscript…

apply plugin: "buildscript"

Luke, now that gradle 1.6 is out I tried out the old configuration assuming that this should work by now. However, having an empty build.gradle file and having the following init.gradle file I am getting an error:

  • Where: Initialization script ‘C:\Users\B13850.gradle\init.gradle’ line: 11

  • What went wrong: A problem occurred evaluating initialization script. > You can’t change a configuration which is not in unresolved state!

Here is the init.gradle file:

buildscript {

repositories {

maven {

url ‘${artifactory_contextUrl}’ + ‘/plugins-release’

credentials {

username = ‘${artifactory_resolve_username}’

password = ‘${artifactory_resolve_password}’

}

}

dependencies {

classpath(group: ‘org.jfrog.buildinfo’, name: ‘build-info-extractor-gradle’, version: ‘2.0.18’)

}

} }

apply plugin: ‘maven’ apply plugin: ‘artifactory’

Thanks a lot!

Boris

Can you provide the full stacktrace please, via http://gist.github.com.

here it is:

https://gist.github.com/anonymous/5712042

Is that the complete initscript?

Also, it doesn’t make sense to apply the maven or artifactory plugin to an init script, they are applied to projects.