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

497
Visualizações
Gradle Kotlin allprojects dependencies cause build failure

In my Gradle project, I can declare a dependencies block with implementation entries, no problem. When I try to declare something like this, however, I get an error:

allprojects {
    dependencies {
        implementation("...")
    }
}

The error I get:

Could not find method implementation() for arguments [org.mockito:mockito-core:2.25.0]
on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.

I wasn't able to reproduce this with a Java project, so it might have something to do with the Kotlin project. I'm new to Gradle, so I might just be doing something silly? Here's my environment info:

$ gradle --version

------------------------------------------------------------
Gradle 5.2.1
------------------------------------------------------------

Build time:   2019-02-08 19:00:10 UTC
Revision:     f02764e074c32ee8851a4e1877dd1fea8ffb7183

Kotlin DSL:   1.1.3
Kotlin:       1.3.20
Groovy:       2.5.4
Ant:          Apache Ant(TM) version 1.9.13 compiled on July 10 2018
JVM:          1.8.0_112 (Oracle Corporation 25.112-b15)
OS:           Windows 10 10.0 amd64

Minimal reproduction

I can reproduce the issue with a minimal project.

build.gradle:

plugins {
    id 'org.jetbrains.kotlin.jvm' version '1.3.21'
}

group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'

repositories {
    mavenCentral()
}

// This works.
dependencies {
    implementation 'org.mockito:mockito-core:2.25.0'
}

// Causes an error. Using a random dependency to reproduce the issue.
allprojects {
    dependencies {
        implementation 'org.mockito:mockito-core:2.25.0'
    }
}

settings.gradle:

rootProject.name = 'demo'

// Removing this line causes the error to go away, but means the module is missing.
include 'submodule'

submodule/build.gradle

// Empty file. I've tried adding various plugins (java / kotlin) to no avail.
over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

The issue in your build.gradle is you are trying to use a build dependency configuration, in this case implementation without specifying the java plugin. The gradle docs says;

The Java plugin adds a number of dependency configurations to your project, as shown below. Tasks such as compileJava and test then use one or more of those configurations to get the corresponding files and use them, for example by placing them on a compilation or runtime classpath.

One way to fix this is to include java plugin as below (I have tested on 5.2.1 and it worked fine);

allprojects {
    apply plugin: 'java'
    dependencies {
        implementation 'org.mockito:mockito-core:2.25.0'
    }
}

The relationship of build configuration to the java plugin has been comprehensively described on https://docs.gradle.org/current/userguide/java_plugin.html#sec:java_plugin_and_dependency_management

and

https://docs.gradle.org/current/userguide/managing_dependency_configurations.html#managing_dependency_configurations

Also, make sure you don't duplicate this dependency (or any other which is declared in the root or for all projects) in subprojects.

over 4 years ago · Santiago Trujillo Relatório
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