Configure IntelliJ auto-completion for gradle script in kotlin - intellij-idea

I am trying out gradle-script-kotlin with simple hello-world application in IntelliJ. But IntelliJ auto-completion doesn't popup in build.gradle.kts file.
https://github.com/gradle/gradle-script-kotlin/tree/master/samples/hello-world
build.gradle.kts:
apply<ApplicationPlugin>()
configure<ApplicationPluginConvention> {
mainClassName = ".HelloWorld"
}
configure<JavaPluginConvention> {
setSourceCompatibility(1.8)
setTargetCompatibility(1.8)
}
repositories {
jcenter()
}
dependencies {
testCompile("junit:junit:4.12")
}
settings.gradle:
rootProject.buildFileName = 'build.gradle.kts'
I have IntelliJ kotlin plugin and gradle plugin installed and using gradle 3.0. The sample application works with gradle commands.
How to configure IntelliJ to enable auto-completion on build.gradle.kts file?
I'm using IntelliJ 2016.2.2 with kotlin plugin version: 1.0.3-release-IJ2016.1-120

Had the same problem. Gradle script Kotlin requires version 1.1x of the IntelliJ Kotlin plugin.
Follow these steps to install it:
https://github.com/gradle/gradle-script-kotlin/tree/master/samples#install-idea-kotlin-plugin
The regular update channel only updates to version 1.0.3x right now.
Update 18/06:
The github readme has been updated to include:
(Note: this version will not work with the official Gradle 3.0 release, stick to the official EAP 1.1 from JetBrains if you intend to use Gradle 3.0)
If you manually installed version 1.1.0-dev-2222 earlier, uninstall it and restart IntelliJ.
Install version 1.1.x from the EAP Channel
This version works with Kotlin-Script in Gradle 3.0.
In IntelliJ, press:
Tools => Kotlin => Configure Kotlin Updates.
Select
Early Access Preview 1.1
and press
Check for updates now.
Download the latest plugin.
If it gives an error, just restart IntelliJ, it will have installed the plugin.

I tried gradle 3.1 with kotlin-plugin-1.1.0-dev-2222.zip in intellij 2.5. And it works for me.
Here is my intellij version:
IntelliJ IDEA 2016.2.5
Build #IC-162.2228.15, built on October 14, 2016
JRE: 1.8.0_112-release-287-b2 x86_64
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
And the steps:
1, Download the kotlin-plugin-1.1.0-dev-2222.zip in https://github.com/gradle/gradle-script-kotlin/tree/master/samples and install the plugin in Idea
2, Create a gradle java project in Idea, and choose to use gradle wrapper
3, In the terminal, under the project directory, use "./gradlew wrapper --gradle-version=3.1" to switch to gradle 3.1
4, Create a file "build.gradle.kts" under the root directory of the project
5, Add rootProject.buildFileName = 'build.gradle.kts' in the settings.gradle file
6, Add codes in build.gradle.kts, and if the auto-completion does not work, try "Refresh all projects" in the Gradle Tool Window.
7, If it still not work, restart your Idea
Here is a github repo: https://github.com/kolyjjj/gradle-kotlin-test

Try re-importing the project by selecting settings.gradle.

Related

How to determine Kotlin version for old Gradle version?

I have an existing project using Gradle 5.6.3, which is currently building Java-only Android. I'd like to add a library in Kotlin.
I had IntelliJ generate a library module, which gave me the following configuration:
plugins {
id 'org.jetbrains.kotlin.android'
}
and in my parent project
buildscript {
dependencies {
classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.30'
}
}
However, when I run this, it fails, saying The current Gradle version 5.6.3 is not compatible with the Kotlin Gradle plugin. Please use Gradle 6.1.1 or newer, or the previous version of the Kotlin plugin.
Because of reasons, upgrading Gradle is not an option for the project right now. So I want to satisfy Gradle by using "the previous version".
I already looked at the compatibility matrix, but that only says that Gradle is tested with Kotlin 1.3.72 through 1.6.0., which isn't helpful.
So, which version of the kotlin-gradle-plugin do I need if I want to stay on Gradle 5.6.3?

InteliJ desktop compose project compile issue

I am making a desktop app using Kotlin compose(IntelliJ version 2021.2.1). My project is still running but I am getting these compile errors in the kotlin compose code.
"Check your module classpath for missing or conflicting dependencies"
Here are my project configurations
As a solution, I removed cashe in .gradle and restart IDE with invalidating cashe but didn't work. and changed JDK versions and kotlin versions as well but still getting the same output.
Your project uses pretty outdated versions of both kotlin and Compose.
Check out that your Compose Multiplatform IDE Support plugin is up to date, the latest version for today is 1.0.0-alpha4-build331
Latest versions of plugins for build.gradle.kts:
kotlin("jvm") version "1.5.21"
id("org.jetbrains.compose") version "1.0.0-alpha3"

How to solve Could not find com.android.tools.build:gradle:4.1.1.?

Can't build react native app in android studio.
I tried:
Sync Project with Gradle Files, but I can't do it because of an
error
File -> Invalidate Caches/ Restart
Clear cache from $HOME/.gradle
Delete $HOME/.gradle
Change com.android.tools.build:gradle version on 2.3.0, because it's
the latest version in this list
(https://repo.jfrog.org/artifactory/libs-release-bintray/com/android/tools/build/gradle/), but when I use npx react-native init projectName, used Android Plugin Version 4.1.2, but this version there isn't in this list.
Also know the difference between Gradle, Android Gradle Plugin,
Gradle Wrapper, already read https://developer.android.google.cn/studio/releases/gradle-plugin?hl=en. I tryied to use the latest Gradle v. 6.8.2 and Android Gradle Plugin v. 4.1.2, it also didn't help to build the project.
Change distributionUrl in
projectName/android/gradle/wrapper/gradle-wrapper.properties
Change in File->Settings->Build, Execution, Deployment->Gradle use
Gradle from Specified location and set C:/Gradle/gradle-6.8.2, it didn't help and left it at default
I know there are exactly the same questions on stackoverflow and on github, but the solutions haven't helped.
Build output:
Could not find com.android.tools.build:gradle:4.1.1.
Searched in the following locations:
- https://jcenter.bintray.com/com/android/tools/build/gradle/4.1.1/gradle-4.1.1.pom
If the artifact you are trying to retrieve can be found in the repository but without metadata in 'Maven POM' format, you need to adjust the 'metadataSources { ... }' of the repository declaration.
Required by:
project :react-native-settings
Add google Maven repository and sync project
Open File
Now used:
Gradle v. 6.5
Android Gradle Plugin v. 4.1.2
gradle-wrapper 6.5-all
Android Studios 4.1.2
Android SDK Platform: Android 10, 9, 8.1, 8.0, 7.1.1, 7.0
Your google Maven library is missing. Rebuild project after adding it

how to downgrade the kotlin version

I use map_view library in flutter project
the error was
The Android Gradle plugin supports only Kotlin Gradle plugin version 1.2.51 and higher. Project 'map_view' is using version 1.2.50.
Try this.
Go to YourFlutterProject/android/build.gradle
Replace to.
buildscript{
ext.kotlin_version = '1.3.10'
....

How can I upgrade react-native gradle version

I need help.
I can't upgrade gradle version of my react-native project.
I try a lot of things, downloaded last version of Android Studio & SDK Tools etc.
I changed this file \android\gradle\wrapper\gradle-wrapper.properties, I tried to upgrade using npm install -g react-native-git-upgrade but still I can't upgrade it.
When I react-native eject It's exports
"distributionUrl=https://services.gradle.org/distributions/gradle-2.14.1-all.zip"
Waiting for answers.
In android/build.gradle you have to edit this line
classpath 'com.android.tools.build:gradle:x.y.z'
Change x.y.z with the version you want. Edit it with Android Studio then click Sync now
In {yourProject}\android\gradle\wrapper\gradle-wrapper.properties, update:
distributionUrl=https\://services.gradle.org/distributions/gradle-{your version}.zip
Find your version of gradle with
gradle --version
You may need to install gradle wrapper if you haven't already.
you can go to https://services.gradle.org/distributions/ and check that latest -all.zip version of gradle and update the same in your gradle-wrapper.properties file. When you run your react-native app the next time, your gradle will first get upgraded and then run.
There are two things
Android Gradle Plugin
You can see the version of it in android/build.gradle file and update it using Daniel's answer here
Gradle version
You can see this in android\gradle\wrapper\gradle-wrapper.properties file and update it using the answer mentioned here
To know the difference between them refer following links:
https://developer.android.com/studio/releases/gradle-plugin
difference between android gradle plugin and gradle
Open Android Studio and navigate to File → Project Structure
Then click on the Project option.
then choose the latest version of Gradle. After that click on Ok.
From Gradle's site:
https://gradle.org/install/#with-the-gradle-wrapper
Upgrade with the Gradle Wrapper If your existing Gradle-based build
uses the Gradle Wrapper, you can easily upgrade by running the wrapper
task, specifying the desired Gradle version:
$ ./gradlew wrapper --gradle-version=6.6.1 --distribution-type=bin
Note that it is not necessary for Gradle to be installed to use the
Gradle wrapper. The next invocation of gradlew or gradlew.bat will
download and cache the specified version of Gradle.
$ ./gradlew tasks
Downloading https://services.gradle.org/distributions/gradle-6.6.1-bin.zip ...
Run these commands in your project's android folder
I had opened my project in Terminal and ran open -a /Applications/Android\ Studio.app to open Android Studio but so that it can access node to download my gradle version which it did automatically.
Learned from this original post: React Native on Android: Cannot run program "node": error=2, No such file or directory
For react native
Go to File -> Project Structure -> Change gradle version to 6.1.1 plugin version to 4.0.0
Try different combinations
Use this link - https://developer.android.com/studio/releases/gradle-plugin.html#updating-gradle