Connected my module and in build.gradle
write next:
plugins {
id("org.jlleitschuh.gradle.ktlint")
kotlin("jvm")
}
dependencies {
compileOnly(kotlin("stdlib"))
compileOnly(kotlin("reflect"))
compileOnly(kotlin("script-runtime"))
compileOnly("com.pinterest.ktlint:ktlint-core:0.34.2")
}
and get next error:
startup failed: build file '/home/vadimm/AndroidStudioProjects/homework/target-list/custom_ktlint_rules/build.gradle': 3: only id(String) method calls allowed in plugins {} script block
See https://docs.gradle.org/5.1.1/userguide/plugins.html#sec:plugins_block for information on the plugins {} block
@ line 3, column 5. kotlin("jvm") ^
1 error
Also tried write smth like this:
apply plugin: 'kotlin'
or
plugins {
id 'kotlin'
}
but it is not successful
For this, you have to connect your PC to the internet and you have to open your Android studio. After opening your project click on the Sync Project with Gradle files option. This will automatically download the new Gradle files and will fix the issue which is caused by the Gradle files.
If gradle --version works, but all of your builds fail with the same error, it is possible there is a problem with one of your Gradle build configuration scripts. You can verify the problem is with Gradle scripts by running gradle help which executes configuration scripts, but no Gradle tasks.
Android studio -> Settings -> build tools -> gradle -> Project-level settings -> select Use default gradle wrapper(recommended). And sync gradle and rebuild your project.
I have faced similar issue. Following solution works for me. Good Luck!!
plugins {
kotlin("kapt")
id("dagger.hilt.android.plugin")
}
to
plugins {
id("kotlin-kapt")
id("dagger.hilt.android.plugin")
}
If anyone runs into this error while trying to use Kotlin DSL and wants to keep it: make sure your file is build.gradle.kts
, not build.gradle
Resolved with next solution:
apply plugin: 'kotlin'
dependencies {
compileOnly("org.jetbrains.kotlin:kotlin-stdlib")
compileOnly("org.jetbrains.kotlin:kotlin-reflect")
compileOnly("org.jetbrains.kotlin:kotlin-script-runtime")
compileOnly("com.pinterest.ktlint:ktlint-core:0.34.2")
}
kotlin("jvm") is Gradle kotlin-dsl syntax. For common Gradle syntax use apply plugin: 'kotlin' kotlin("..") is also from Gradle kotlin-dsl
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With