Kotlin 1.3.20 with Gradle 5.1.1 compileKotlin2Js execute hot reload - gradle

In Kotlin 1.3.20 and Gradle 4.10.2, it is possible to hot reload js files with the following in Gradle:
task watch {
inputs.files 'src/main'
doLast {
compileKotlin2Js.execute()
}
}
However, then we get a warning of:
Deprecated Gradle features were used in this build, making it incompatible with Gradle 5.0.
With Kotlin 1.3.20 / Gradle 5.1.1, the deprecation warning goes away, but the compileKotlin2Js.execute() results in the following error:
Parameter specified as non-null is null: method org.jetbrains.kotlin.gradle.tasks.AbstractKotlinCompile.execute, parameter inputs
Is there a way to compileKotlin2Js.execute() for hot-reloading js files with Kotlin 1.3.20 / Gradle 5.1.1?

Answering own question, got Kotlin 1.3.72 multiplatform project working with Gradle 6.3 with Kotlin DSL: https://github.com/alexoooo/sample-multiplatform-boot-react
When developing, there are two processes:
Java back-end from IDE, run with: --server.port=8081
Webpack proxy with hot-reload: gradlew -t :proj-js:run
Note that Kotlin multiplatform projects are currently experimental, and some of the details are likely to change as the new IR is introduced: https://blog.jetbrains.com/kotlin/2020/03/kotlin-1-4-m1-released/

Related

Spring boot gradle project with kotlin setup issue

Hello i want to create a Spring boot app with kotlin and Gradle but i have this issue in the plugins line, it doens't recognize any plugin i add ,i couldn't undrestand what's missing, i'm using Gradle 6.3v , jdk 8
Error:
Error
And that's the build.gradle file
build.gradle.kts
Your first plugin declaration has a typo in the version:
kotlin("jvm") version "1.3.11" needs to be kotlin("jvm") version "1.3.71"
I would start by changing that so all usages of kotlin plugins are aligned on a recent version.
If that does not resolve the problem, try running the build from the CLI with the added flag --stacktrace which may tell you more about why is the plugin not found.

Can't build kotlin files using gradle kotlin DSL in Intellij idea

I'm trying to set up a kotlin project with gradle kotlin DSL as build system in IntelliJ idea,but I'm getting below error when try to run buil.gradle.kts file. I have tried with different kotlin compiler version but no luck.
warning: default scripting plugin is disabled: The provided plugin org.jetbrains.kotlin.scripting.compiler.plugin.ScriptingCompilerConfigurationComponentRegistrar is not compatible with this version of compiler
error: unable to evaluate script, no scripting plugin loaded
IntelliJ Version:
Gradle version : 6.3
build.gradle.kts
plugins {
id("org.jetbrains.kotlin.jvm") version "1.3.70"
// Apply the application plugin to add support for building a CLI application.
application
}
repositories {
// Use jcenter for resolving dependencies.
// You can declare any Maven/Ivy/file repository here.
jcenter()
}
dependencies {
// Align versions of all Kotlin components
implementation(platform("org.jetbrains.kotlin:kotlin-bom"))
// Use the Kotlin JDK 8 standard library.
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
// Use the Kotlin test library.
testImplementation("org.jetbrains.kotlin:kotlin-test")
// Use the Kotlin JUnit integration.
testImplementation("org.jetbrains.kotlin:kotlin-test-junit")
}
application {
// Define the main class for the application.
mainClassName = "Music.AppKt"
}
The correct way to build a Gradle project in IDEA is to execute "Main menu | Build | Build project" if your build is delegated to Gradle in IDEA settings, or execute one of the build tasks in Gradle tool window: http://jetbrains.com/help/idea/work-with-gradle-tasks.html
However, the behavior you described can be considered a usability problem, I created an issue https://youtrack.jetbrains.com/issue/KT-37814, please follow it for updates.

Trying to upgrade from Gradle 4.10 to 5.0, but am getting unresolved references errors

I'm trying to upgrade to Gradle 5, but am getting "Unresolved reference" errors when compiling - most of which are internal libraries that are within a classpath. Additionally, the javax.inject library somehow doesn't exist anymore.
I've tried individually adding in the libraries that are now missing, but it then fails to build for some reason (with some sort of abstract method error).
buildscript {
...
dependencies {
classpath "some-internal-classpath"
}
}
How do I get it so that Gradle 5 will be able to resolve those references from my internal classpath + have javax.inject again?
When upgrading to Gradle 5.x from Gradle 4.x, there is one change in behaviour that can cause what you observe:
Gradle 5.x will honour the compile / runtime separation of dependency declarations in POM files. This means that a transitive library that is in the runtime scope of Maven is no longer visible at compilation.
So the fix is usually to find out the libraries you were using in your code but did not depend upon explicitly.
A useful method for doing that investigation is to leverage the dependencies task of Gradle, focused on the compileClasspath, effectively running ./gradlew dependencies --configuration compileClasspath with Gradle 4.x and 5.x and analysing the differences.

publishing to mavenLocal using build.gradle.kts

I'm trying to publish an artifact to ~/.m2 (maven-local) and as a Gradle newbie, i'm not sure what i'm missing
All the examples i've seen so far suggests using a publishing block which throws deprecation warnings when i run any Gradle commands.
Also including the maven-publish plugin without any publishing block causes the same warnings.
repositories {
mavenLocal()
jcenter()
}
plugins {
`maven-publish`
kotlin("jvm") version("1.3.10")
id("org.jetbrains.dokka") version "0.9.16"
}
As part of making the publishing plugins stable, the 'deferred
configurable' behavior of the 'publishing {}' block has been
deprecated. In Gradle 5.0 the
'enableFeaturePreview('STABLE_PUBLISHING')' flag will be removed and
the new behavior will become the default. Please add
'enableFeaturePreview('STABLE_PUBLISHING')' to your settings file and
do a test run by publishing to a local repository. If all artifacts
are published as expected, there is nothing else to do. If the
published artifacts change unexpectedly, please see the migration
guide for more details:
https://docs.gradle.org/4.10.2/userguide/publishing_maven.html#publishing_maven:deferred_configuration.
If it actually published to maven-local, i might have ignored the warning for now, but it's not publishing at all, neither does gradle publishToMavenLocal, it simply says BUILD SUCCESSFUL in __s with the above warning.
Trying the recommended route (according to the link) of adding the publishing block inside a subprojects block causes lots of red in intellij
Not sure if that's Kotlin DSL or not ... trying something else that was shown on the Kotlin DSL version of the Gradle Docs:
Any idea what i'm missing?
Here's my Gradle version and other relevant info (IntelliJ has Kotlin 3.1.0)
gradle -version
------------------------------------------------------------
Gradle 4.10.2
------------------------------------------------------------
Build time: 2018-09-19 18:10:15 UTC
Revision: b4d8d5d170bb4ba516e88d7fe5647e2323d791dd
Kotlin DSL: 1.0-rc-6
Kotlin: 1.2.61
Groovy: 2.4.15
Ant: Apache Ant(TM) version 1.9.11 compiled on March 23 2018
JVM: 1.8.0_151 (Oracle Corporation 25.151-b12)
OS: Mac OS X 10.14.1 x86_64
I think all you need to do is apply the maven plugin then run the install task. Details of how to apply the plugin are here, e.g. using the Kotlin DSL you'd have:
plugins {
maven
}
Then you just run the install task, e.g. from your IDE (the Gradle window in IntelliJ in your case) or a command line, e.g. ./gradlew install.
Regarding applying the maven plugin, if you're new to Gradle you probably want to get clear on the Gradle plugins DSL (which the above code snippet is an example of). If you're not using that then the way you apply the plugin is slightly different (e.g. you have to use the apply command). There are details here. Note that the decision about whether to use the Gradle plugins DSL is different from the choice of using Groovy or Kotlin for the language in which you write the build.gradle file.

Use of the 'compileOnly' scope in Android projects?

I'm using Gradle 2.12 (or newer) with an appropriate version of the Android Gradle plugin in my project. Gradle 2.12 introduced the compileOnly configuration, so why do I get an error when I try to use it?
Could not find method compileOnly() for arguments
Note the following sentence from the Gradle 2.12 release notes regarding the new compileOnly configuration (my emphasis):
You can now declare dependencies to be used only at compile time in conjunction with the Java plugin.
So the Java Gradle plugin is a component we need to consider when answering this question. We can find the compileOnly configuration declared in the Java Gradle plugin source code for new enough versions.
However, the Android Gradle plugins do not direct extend the Java Gradle plugin. In fact, I believe the Android plugins represent a sort of 'frankenplugin', with some functionality borrowed but not inherited from the Java plugin. The following chunks of source code support this idea.
From the base Android plugin class:
project.apply plugin: JavaBasePlugin
The Android Gradle plugins therefore incorporate functionality from the base Java Gradle plugin, not from the full Java Gradle plugin. Moreover, there is an explicit check that the full Java Gradle plugin is not applied alongside an Android Gradle plugin:
// get current plugins and look for the default Java plugin.
if (project.plugins.hasPlugin(JavaPlugin.class)) {
throw new BadPluginException(
"The 'java' plugin has been applied, but it is not compatible with the Android plugins.")
}
Based on this information, my guess is that compileOnly has just not been manually ported from the Java Gradle plugin to the Android Gradle plugin yet. It probably won't appear before we get an Android Gradle plugin with minimum Gradle version set at 2.12 or higher.
Simple use provided instead of compileOnly
See https://github.com/google/auto/issues/324#issuecomment-212333044

Resources