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

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.

Related

Kotlin 1.3.20 with Gradle 5.1.1 compileKotlin2Js execute hot reload

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/

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.

Need help on java2wsdl using gradle

I have a java project to which I build it using gradle build and generate a war file.
Currently my requirement is to generate WSDL file at the time of build from java classes. I came to know about axis2-java2wsdl-maven-plugin and found the syntax of applying it in gradle. But I am not able to get the tasks list or the example of using this plugin in gradle to generate the WSDL file using this plugin.
Can anybody let me know of how to use this plugin or any other help so that I can generate WSDL file form my java classes.
Dependency section which I included in build.gradle:
repositories {
mavenCentral()
}
dependencies {
'org.apache.axis2:axis2-java2wsdl-maven-plugin:1.6.2'
}
axis2-java2wsdl-maven-plugin is a maven plugin not a gradle one.
Moreoever, gradle plugins must be defined in a buildscript closure or a plugins one if you want to use the new plugins DSL.
Here, you are just using the maven plugin as a regular dependency for your project.
As far as i know, there is not "java2wsdl" gradle plugin.

gradle fails to compile java classes using kotlin class

I have a gradle 4.1 multiproject containing a "projectA" containing 2 subfolders "api" and "implementation".
The multiproject uses kotlin and java-library plugins defined in the subprojects section of the main build.gradle.
The implementation project avec a API dependency to :projectA:api
In the api folder I have kotlin and java files inside 'src/main/java' and in the implementation project I'm creating a new instance of a kotlin class from the API.
Inside Intellij Idea, I don't have any compilation errors ; but when I compile the whole project using gradle I have an error: cannot find symbol. It is as if the compileJava doesn't have access to the folder kotlin-classes.
Inside the build/kotlin-classes, I see my file.class
The class file is on build/classes dir also
Details of the error :
Task :projectA:api:compileKotlin
Using kotlin incremental compilation
Task :projectA:implementation:compileJava
(...) error: cannot find symbol (the import fails)
Update 1 : removing java-library solved my problem
This is a known issue of the java-library plugin: when used in a project with another JVM language (Kotlin, Scala, Groovy etc.) , it does not register the classes of the other language so that the dependent projects get them as they consume the classes.
Fortunately, it has a workaround as well. Adapted to Kotlin, it would look like:
configurations {
apiElements {
outgoing.variants.getByName('classes').artifact(
file: compileKotlin.destinationDir,
type: ArtifactTypeDefinition.JVM_CLASS_DIRECTORY,
builtBy: compileKotlin)
}
}
If you use Kapt1, it's file: compileKotlinAfterJava.destinationDir, and for Gradle versions lower than 4.0 use builtBy: copyMainKotlinClasses instead.
This issue is also tracked in the Kotlin issue tracker: KT-18497, follow that issue to see when it's fixed on the Kotlin Gradle plugin side, so that the above workaround will be no more necessary.

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