project.plugins.hasPlugin("java") returns false when the new plugin mechanism is used

My plugin checks if Java plugin is applied to generate verbose error message (instead of “missing sourceSets property”). I use “!project.plugins.hasPlugin(“java”)”. Unfortunately it doesn’t work when the new plugin mechanism is used.

plugins {
  id "java"
  id "info.solidsoft.pitest" version "1.1.0"
}

Is that expected behavior? If yes, how can I check if in the project the java plugin has be applied?

When using the new plugin application mechanism core plugins are internally applied using their fully qualified names and they are located in the ‘org.gradle’ namespace, so for java plugin the id passed to ‘hasPlugin()’ should be ‘org.gradle.java’. This will be improved in 2.3 and a core plugin will be reported as applied if you pass either a qualified or unqualified id to ‘hasPlugin()’.

Thanks Marcin. I already switched to apply Java plugin myself, but it’s good to know. Maybe I will revert that behavior in the next version.

Marcin, I tried it and unfortunately it doesn’t work. Even for:

plugins {
  id "java"
  id "info.solidsoft.pitest" version "1.1.2"
}

or

plugins {
  id "org.gradle.java"
  id "info.solidsoft.pitest" version "1.1.2"
}

‘hasPlugin(“org.gradle.java”)’ fails. In fact there is only one already applied plugin:

org.gradle.api.plugins.HelpTasksPlugin

This is with 2.3?

No, with 2.2.1.

2.2.1 didn’t have the fixes, but 2.3 does.

I will try it. Nevertheless I will have to stay with the old solution to allow people with earlier Gradle versions to use my plugin.

Btw, where can I find the latest build for 2.3 branch? I see no RC versions and nighty builds are for 2.4 line.

We have branched for release already so nightlies point at 2.4. It’s a bit slow over Christmas but we should be releasing some RCs for 2.3 soonish. You can always use nightlies (which are basically built off master) until then.

There’s a release snapshot (pre RC) published here: https://services.gradle.org/distributions-snapshots/gradle-2.3-20150109044722+0000-all.zip