Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

294
Views
Write a Gradle Plugin that reacts to multiple plugins

I am trying to write a new Gradle plugin which requires the application of two plugins: either java or java-library, or maven-publish. I am writing the plugin in Kotlin.

I can easily, following the Gradle guide, make the plugin react to a single plugin application:

project.plugins.withType(MavenPublishPlugin::class.java) {
    // My stuff
}

But I can't do the same for requiring two plugin applications:

project.plugins.withType(JavaPlugin::class.java) {
    project.plugins.withType(MavenPublishPlugin::class.java) {
        // My stuff
    }
}

In the second case, launching with:

Case 1: as expected

plugins {
    id("java")
    id("maven-publish")
    id("org.danilopianini.publish-on-central")
}

runs the plugin as expected

Case 2: non applied, as expected

using:

plugins {
    id("java")
    id("org.danilopianini.publish-on-central")
}

does not apply the plugin, as expected

Case 3: applied, it should have not been

but, finally:

plugins {
    id("maven-publish")
    id("org.danilopianini.publish-on-central")
}

tries to apply the plugin and fails with:

FAILURE: Build failed with an exception.

* Where:
Build file '/tmp/junit876726632157783854/build.gradle.kts' line: 1

* What went wrong:
An exception occurred applying plugin request [id: 'org.danilopianini.publish-on-central']
> Failed to apply plugin [id 'org.danilopianini.publish-on-central']
   > SoftwareComponentInternal with name 'java' not found.

* Try:
Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Exception is:
org.gradle.api.plugins.InvalidPluginException: An exception occurred applying plugin request [id: 'org.danilopianini.publish-on-central']
[cut]
Caused by: org.gradle.api.internal.plugins.PluginApplicationException: Failed to apply plugin [id 'org.danilopianini.publish-on-central']
    ... 128 more
Caused by: org.gradle.api.UnknownDomainObjectException: SoftwareComponentInternal with name 'java' not found.
    at org.gradle.api.internal.DefaultNamedDomainObjectCollection.createNotFoundException(DefaultNamedDomainObjectCollection.java:489)
    at org.gradle.api.internal.DefaultNamedDomainObjectCollection.getByName(DefaultNamedDomainObjectCollection.java:323)

Which looks to me as an attempt to apply the plugin regardless the fact that the Java plugin was not applied.

Do you know any way to configure a plugin to react to multiple plugin applications?

over 4 years ago · Santiago Trujillo
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!