What are the requirements for gradle.kts generated by spring initializr? - kotlin

I modified the build.gradle file of the newly created gradle project named build.gradle.kts, and then copied the build.gradle.kts content of the demo project generated by spring initializr, and then build, this file reported a lot of errors, but spring initializr project can be built correctly.
The two build.gradle.kts are exactly the same. What's wrong?
This is the wrong screenshot https://s2.ax1x.com/2019/08/21/mNvASA.png
This is the correct screenshot https://s2.ax1x.com/2019/08/21/mNvEQI.png
This is the content
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins {
id("org.springframework.boot") version "2.1.7.RELEASE"
id("io.spring.dependency-management") version "1.0.8.RELEASE"
kotlin("jvm") version "1.2.71"
kotlin("plugin.spring") version "1.2.71"
}
group = "com.example"
version = "0.0.1-SNAPSHOT"
java.sourceCompatibility = JavaVersion.VERSION_1_8
repositories {
mavenCentral()
}
dependencies {
api("org.springframework.boot:spring-boot-starter")
api("org.jetbrains.kotlin:kotlin-reflect")
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
testImplementation("org.springframework.boot:spring-boot-starter-test")
}
tasks.withType<KotlinCompile> {
kotlinOptions {
freeCompilerArgs = listOf("-Xjsr305=strict")
jvmTarget = "1.8"
}
}

Related

Unresolved reference for gradle dependency

All the classes of the library are shown in the libs folder but when I try to use any reference to it, it just says it is an unresolved reference.
Unresolved reference error
build.gradle.kts:
plugins {
kotlin("jvm") version "1.8.0"
kotlin("plugin.serialization") version "1.8.0"
id("com.github.johnrengelman.shadow") version "7.1.2"
id("io.papermc.paperweight.userdev") version "1.3.6"
}
group = "me.supehsloht"
version = "1.0-SNAPSHOT"
repositories {
mavenCentral()
maven("https://repo.rapture.pw/repository/maven-snapshots/")
}
dependencies {
compileOnly("org.jetbrains.kotlin:kotlin-stdlib:1.8.0")
compileOnly("org.jetbrains.kotlinx:kotlinx-serialization-json:1.4.1")
compileOnly("com.charleskorn.kaml:kaml:0.49.0")
paperDevBundle("1.19.3-R0.1-SNAPSHOT")
compileOnly(files("libs/Core.jar"))
compileOnly(files("libs/AdvancedSlimeWorldManagerAPI.jar"))
}
java {
toolchain.languageVersion.set(JavaLanguageVersion.of(17))
}
tasks {
compileJava {
options.encoding = Charsets.UTF_8.name()
options.release.set(17)
}
compileKotlin {
kotlinOptions.jvmTarget = "17"
}
reobfJar {
outputJar.set(layout.buildDirectory.file("libs/${project.name.capitalize()}.jar"))
}
}
I already had this problem, then it was fixed by not shading the kotlin stdlib into the jar but that didn't work this time.

IntelliJ IDEA could not found the kotlin test dependency Library, but I have kotlin("test") for gradle.build.ks

I created a kotlin project through the project creation wizard of Intellij IDEA.
I just created a test file to verify the demo of kotlin official website.
A demo for Intellij IDEA, but it not find to 'kotlin.test.Test'.
internal class ATest {
#kotlin.test.Test
fun sum() {
}
}
IDEA UI IMAGE
This is my 'gradle.build.ks' file.
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins {
kotlin("jvm") version "1.7.10"
}
group = "org.example"
version = "1.0-SNAPSHOT"
repositories {
mavenCentral()
}
dependencies {
testImplementation(kotlin("test"))
}
tasks.test {
useJUnitPlatform()
}
tasks.withType<KotlinCompile> {
kotlinOptions.jvmTarget = "1.8"
}

Kotlin NoSuchMethodError after installing a library that enables a plugin

I want to experience a library called arrow analysis
My build.gradle.kts file looks as follows:
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins {
kotlin("jvm") version "1.7.10"
}
group = "org.example"
version = "1.0-SNAPSHOT"
repositories {
mavenCentral()
}
dependencies {
testImplementation(kotlin("test"))
implementation("io.arrow-kt:arrow-core:1.1.2")
}
buildscript {
dependencies {
classpath("io.arrow-kt.analysis.kotlin:io.arrow-kt.analysis.kotlin.gradle.plugin:2.0")
}
}
apply(plugin = "io.arrow-kt.analysis.kotlin")
tasks.test {
useJUnitPlatform()
}
tasks.withType<KotlinCompile> {
kotlinOptions.jvmTarget = "1.8"
}
after an attempt to build the project, I get the following error:
java.lang.NoSuchMethodError: 'org.jetbrains.kotlin.psi.KtExpression org.jetbrains.kotlin.resolve.calls.callUtil.CallUtilKt.getReceiverExpression(org.jetbrains.kotlin.resolve.calls.model.ResolvedCall)'
at arrow.meta.plugins.analysis.phases.analysis.solver.ast.kotlin.KotlinResolvedCall.getReceiverExpression(KotlinResolvedCall.kt:37)
at arrow.meta.plugins.analysis.phases.analysis.solver.ResolvedCallUtilsKt.allArgumentExpressions(ResolvedCallUtils.kt:75)
at arrow.meta.plugins.analysis.phases.analysis.solver.ResolvedCallUtilsKt.arg(ResolvedCallUtils.kt:119)
at arrow.meta.plugins.analysis.phases.analysis.solver.check.ExpressionsKt.controlFlowAnyFunction(Expressions.kt:438)
at arrow.meta.plugins.analysis.phases.analysis.solver.check.ExpressionsKt.checkCallExpression(Expressions.kt:397)
at arrow.meta.plugins.analysis.phases.analysis.solver.check.ExpressionsKt.fallThrough(Expressions.kt:260)
at arrow.meta.plugins.analysis.phases.analysis.solver.check.ExpressionsKt.access$fallThrough(Expressions.kt:1)
at arrow.meta.plugins.analysis.phases.analysis.solver.check.ExpressionsKt$checkExpressionConstraints$2.invoke(Expressions.kt:244)
at arrow.meta.plugins.analysis.phases.analysis.solver.check.ExpressionsKt$checkExpressionConstraints$2.invoke(Expressions.kt:157)
at arrow.meta.continuations.ContSeq$flatMap$1.invokeSuspend(ContSeq.kt:60)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
I checked the source code, and everything seems to be in place. Did I something wrong as per the instructions to install this library which is denoted as follows:
buildscript {
dependencies {
classpath("io.arrow-kt.analysis.kotlin:io.arrow-kt.analysis.kotlin.gradle.plugin:2.0")
}
}
apply(plugin = "io.arrow-kt.analysis.kotlin")
You need to apply the plugin inside the plugins block and in the same fashion you're applying the Kotlin JVM plugin.
They mention to use it like this on their official docs
plugins {
kotlin("multiplatform") version "1.6.21"
// other plugins
id("io.arrow-kt.analysis.kotlin") version "2.0.2"
}
buildscript {
repositories {
mavenCentral()
}
}

Why won't Gradle find my locally published plugin?

I have one project which contains and publishes a Gradle plugin:
plugins {
`java-gradle-plugin`
`kotlin-dsl`
kotlin("jvm") version "1.5.31"
`maven-publish`
}
project.group = "com.company.gradle"
project.version = "1.0.0"
repositories {
mavenCentral()
gradlePluginPortal()
}
gradlePlugin {
plugins.create("pomPlugin") {
id = "com.company.gradle.pom"
implementationClass = "com.company.gradle.pom.PomPlugin"
}
}
Building this and publishing (via ./gradlew publishToMavenLocal) succeeds without errors. After it completes, my local maven repo ~/.m2/reposiory contains:
./com/company/
./com/company/gradle
./com/company/gradle/pom
./com/company/gradle/pom/maven-metadata-local.xml
./com/company/gradle/pom/1.0.0
./com/company/gradle/pom/1.0.0/pom-1.0.0.jar
./com/company/gradle/pom/1.0.0/pom-1.0.0.module
./com/company/gradle/pom/1.0.0/pom-1.0.0.pom
./com/company/gradle/pom/com.company.gradle.pom.gradle.plugin
./com/company/gradle/pom/com.company.gradle.pom.gradle.plugin/maven-metadata-local.xml
./com/company/gradle/pom/com.company.gradle.pom.gradle.plugin/1.0.0
./com/company/gradle/pom/com.company.gradle.pom.gradle.plugin/1.0.0/com.company.gradle.pom.gradle.plugin-1.0.0.pom
Then I have another project that tries to use the plugin:
buildscript {
repositories {
mavenLocal()
google()
mavenCentral()
gradlePluginPortal()
}
}
plugins {
kotlin("jvm") version "1.6.10"
id("com.company.gradle.pom") version "1.0.0"
}
repositories {
google()
mavenCentral()
mavenLocal()
}
but Gradle cannot resolve the plugin:
* What went wrong:
Plugin [id: 'com.foxit.gradle.pom', version: '1.0.0'] was not found in any of the following sources:
- Gradle Core Plugins (plugin is not in 'org.gradle' namespace)
- Plugin Repositories (could not resolve plugin artifact 'com.foxit.gradle.pom:com.foxit.gradle.pom.gradle.plugin:1.0.0')
Searched in the following repositories:
Gradle Central Plugin Repository
Add this at the top of your settings.gradle file in the project where you want to use your plugin.
pluginManagement {
repositories {
mavenLocal()
gradlePluginPortal()
}
}
The gradlePluginPortal() bit is for "real" gradle plugins which have been published.
The mavenLocal() bit is for your locally published plugins.
The repositories blocks you have in the build.gradle are for dependencies and not plugins.

How to use `com.jetbrains.env.PyEnvTestCase` in my unit tests?

I am developing a plugin for PyCharm which uses custom PythonConsoleRunnerFactory.
Currently am trying to write unit tests to cover the created class and I have found at source code of PyCharm that there is PyEnvTestCase class that is used for console testing but I don't know how to include this class in my project.
I am using Gradle as a build tool. Here is my gradle build script:
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins {
java
kotlin("jvm") version "1.3.61"
id("org.jetbrains.intellij") version "0.6.5"
}
group = "com.uriyyo.evaluate_async_code"
version = "1.8"
repositories {
mavenCentral()
jcenter()
}
dependencies {
implementation(kotlin("stdlib-jdk8"))
testImplementation("junit:junit:4.13")
}
configure<JavaPluginConvention> {
sourceCompatibility = JavaVersion.VERSION_1_8
}
tasks.withType<KotlinCompile> {
kotlinOptions.jvmTarget = "1.8"
}
tasks.test {
useJUnit()
}
intellij {
version = project.properties["ideaVersion"].toString()
type = "PC"
pluginName = "evaluate-async-code"
downloadSources = project.properties["downloadIdeaSources"] == "true"
updateSinceUntilBuild = false
setPlugins("terminal", "python-ce")
}
Is there a way to include PyEnvTestCase to be available for tests?