Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How fix build.gradle?

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

like image 655
Morozov Avatar asked Aug 06 '19 16:08

Morozov


People also ask

How do I fix gradle issues?

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.

Why is my gradle build failing?

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.

How do I reset build gradle?

Android studio -> Settings -> build tools -> gradle -> Project-level settings -> select Use default gradle wrapper(recommended). And sync gradle and rebuild your project.


3 Answers

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")          
}
like image 131
Mansi Sharma Avatar answered Oct 13 '22 00:10

Mansi Sharma


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

like image 31
Oleh Toder Avatar answered Oct 13 '22 01:10

Oleh Toder


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

like image 1
Morozov Avatar answered Oct 13 '22 01:10

Morozov