Sharing a plugin with all projects

I have a project that has two places for code:

  • src/ (server code using java plugin) * client/src (client code, using cpp plugin)

I’d like to share a plugin I’ve written and published to handle some complexities with artifact publishing to an artifact repository. Right now I’m using the plugin by including it in the main build.gradle file (in the project’s root).

build.gradle

buildscript {
  dependencies {
    classpath group: 'com.readytalk', name: 'gradle-readytalk-plugin', version: '0.1.0-SNAPSHOT'
  }
}
  apply plugin: 'readytalk-all'

I can’t seem to figure out how to:

  • share this one plugin that’s on my internal artifact repository with both server (src/) and client (client/src) projects. How can I apply the “readytalk-all” plugin to all projects?

  • use “gradle install” (install is defined in my plugin) which will install both the client and server modules into the local artifact repository

Are ‘src’ and ‘client/src’ truly two projects in the Gradle sense?

I’m not sure what you mean…

They are, if I believe I understand your question correctly. Here’s the project: https://github.com/sgoings/revori

I was mislead because the server code’s project is the parent of the client code’s project, which is rather atypical. So yes, they are two projects. Just wrap the plugin application in ‘allprojects { … }’ and you should be fine.

Ah! I had tried that, received an error and assumed that method wasn’t going to work. I figured out the actual problem, which was with my use of the gradle-properties-plugin (https://github.com/stevesaliman/gradle-properties-plugin).

There isn’t an environmentName setup at the time the properties plugin loads, so it fails at that point.

After adding a few tweaks, your suggestion was successful.

For history’s sake, I had to do:

build.gradle

allprojects {
  ext.environmentName = 'test'
    apply plugin: 'readytalk-all'
}

and then create a gradle-test.properties file in both the src and client/src directory.

Thanks for the advice about the parent/child <-> server/client relationship. I am in the process of moving the server code to a subproject.