Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

295
Visualizações
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
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda