Reputation: 181
I have a problem with Gradle. I'm trying to build a project, but I get an error:
Plugin [id: 'com.google.dagger.hilt', version: '2.36', apply: false] was not found in any of the following sources:
- Gradle Core Plugins (plugin is not in 'org.gradle' namespace)
- Plugin Repositories (could not resolve plugin artifact 'com.google.dagger.hilt:com.google.dagger.hilt.gradle.plugin:2.36')
Searched in the following repositories: Google MavenRepo
Here is my libs.version.toml file:
[versions]
# Plugins
android-gradle-plugin = "7.0.0"
spotless-plugin-gradle = "5.12.5"
# Kotlin
kotlin = "1.5.21"
ktlint = "0.41.0"
# AndroidX
androidx-core-ktx = "1.5.0"
androidx-appcompat = "1.3.0"
# UI
material = "1.3.0"
# Hilt DI
hilt = "2.36"
# JVM Unit Tests
junit = "4.13.2"
# Instrumentation Tests
androidx-junit = "1.1.2"
androidx-espresso-core = "3.3.0"
[plugins]
# Plugins
hilt-gradle-plugin = { id = "dagger.hilt.android.plugin", version.ref = "hilt" }
spotless-plugin-gradle = { id = "com.diffplug.spotless", version.ref = "spotless-plugin-gradle" }
kotlin-gradle-plugin = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" }
android-gradle-plugin = { id = "com.android.tools.build.gradle", version.ref = "android-gradle-plugin"}
[libraries]
# Kotlin
kotlin-stdlib = { module = "org.jetbrains.kotlin:kotlin-stdlib", version.ref = "kotlin" }
# AndroidX
androidx-core-ktx = { module = "androidx.core:core-ktx", version.ref = "androidx-core-ktx" }
androidx-appcompat = { module = "androidx.appcompat:appcompat", version.ref = "androidx-appcompat" }
# UI
material = { module = "com.google.android.material:material", version.ref = "material" }
# Hilt DI
hilt-android = { module = "com.google.dagger:hilt-android", version.ref = "hilt" }
hilt-compiler = { module = "com.google.dagger:hilt-android-compiler", version.ref = "hilt" }
# Hilt DI - JVM / Instrumentation Tests
hilt-testing = { module = "com.google.dagger:hilt-android-testing", version.ref = "hilt" }
# JVM Unit Tests
junit = { module = "junit:junit", version.ref = "junit" }
# Instrumentation Tests
androidx-junit = { module = "androidx.test.ext:junit", version.ref = "androidx-junit" }
androidx-espresso-core = { module = "androidx.test.espresso:espresso-core", version.ref = "androidx-espresso-core" }
app\build.gradle:
plugins {
alias(libs.plugins.hilt.gradle.plugin)
alias(libs.plugins.kotlin.gradle.plugin)
alias(libs.plugins.spotless.plugin.gradle)
}
android {
compileSdkVersion 31
defaultConfig {
applicationId "com.litekite.ime"
minSdkVersion 24
targetSdkVersion 31
versionCode 1
versionName "1.0"
vectorDrawables.useSupportLibrary = true
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
sourceSets {
main.java.srcDirs += "src/main/kotlin"
androidTest.assets.srcDirs += files("$projectDir/schemas".toString())
}
buildTypes {
release {
minifyEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
buildFeatures {
viewBinding = true
dataBinding = true
}
lintOptions {
baseline file("lint-baseline.xml")
warningsAsErrors true
enable "Interoperability"
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_11
targetCompatibility JavaVersion.VERSION_11
}
kotlinOptions {
jvmTarget = JavaVersion.VERSION_11
}
}
kapt {
correctErrorTypes true
}
dependencies {
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation(libs.kotlin.stdlib)
implementation(libs.androidx.core.ktx)
implementation(libs.androidx.appcompat)
implementation(libs.material)
// Hilt
implementation(libs.hilt.android)
kapt(libs.hilt.compiler)
// Hilt - Instrumentation test helpers
androidTestImplementation(libs.hilt.testing)
kaptAndroidTest(libs.hilt.compiler)
// Hilt - Local unit test helpers
testImplementation(libs.hilt.testing)
kaptTest(libs.hilt.compiler)
testImplementation(libs.junit)
androidTestImplementation(libs.androidx.junit)
androidTestImplementation(libs.androidx.espresso.core)
}
biuld.gradle:
plugins {
alias(libs.plugins.hilt.gradle.plugin) apply false
alias(libs.plugins.kotlin.gradle.plugin) apply false
alias(libs.plugins.spotless.plugin.gradle) apply false
}
allprojects {
repositories {
google()
mavenCentral()
}
}
allprojects {
repositories {
google()
mavenCentral()
}
}
spotless {
ratchetFrom 'origin/main'
format 'misc', {
target '**/*.gradle', '**/*.md', '**/.gitignore'
trimTrailingWhitespace()
indentWithSpaces()
endWithNewline()
}
format 'xml', {
target '**/*.xml'
trimTrailingWhitespace()
indentWithSpaces()
endWithNewline()
}
kotlin {
target '**/src/**/*.kt'
ktlint(libs.versions.ktlint.get())
licenseHeaderFile rootProject.file('spotless/copyright.kt')
}
}
I can’t understand what the error is, ChatGPT gives the same answers in a circle. Please help if anyone knows what is the reason and how to fix it. I'm using Gradle 8.0
distributionUrl=https://services.gradle.org/distributions/gradle-8.0-bin.zip
settings.gradle:
pluginManagement {
repositories {
google()
mavenCentral()
gradlePluginPortal()
}
}
rootProject.name = "IME"
include ':app'
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
google()
mavenCentral()
}
}
Upvotes: 2
Views: 2017
Reputation: 4266
Try replacing dagger.hilt.android.plugin
with com.google.dagger.hilt.android
in the libs.version.toml.
hilt-gradle-plugin = { id = "com.google.dagger.hilt.android", version.ref = "hilt" }
If this doesn't help, try also removing this from build.gradle:
allprojects {
repositories {
google()
mavenCentral()
}
}
allprojects {
repositories {
google()
mavenCentral()
}
}
And adding this to setting.gradle:
pluginManagement {
repositories {
google()
mavenCentral()
gradlePluginPortal()
}
}
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
google()
mavenCentral()
}
}
Edit:
There might be a problem with outdated hilt version, try a newer one like 2.44 or 2.50. There is a caveat though, is might be incompatible with other outdated dependencies.
Upvotes: 3