Spring boot gradle project with kotlin setup issue - spring-boot

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.

Related

Trying to run a cloned project with gradle but unable to build

I have cloned a Spring boot project from github and I have opened it in intellij. So I am trying to run the build.gradle but I just get this error:
An exception occurred applying plugin request [id: 'org.springframework.boot', version: '2.3.3.RELEASE']
Failed to apply plugin [id 'org.springframework.boot']
Spring Boot plugin requires Gradle 5 (5.6.x only) or Gradle 6 (6.3 or later). The current version is Gradle 5.2
This is the plugin:
plugins {
id 'org.springframework.boot' version '2.3.3.RELEASE'
id 'io.spring.dependency-management' version '1.0.10.RELEASE'
id 'java'
}
What is going on here?
You have Gradle version 5.2. The error states that the Spring Boot plugin specifically requires either 5.6.x (e.g., 5.6.4) or a version greater than or equal to 6.3 (e.g., 6.3, 6.6.1).
You need to upgrade your Gradle version to a 5.6 variant or a newer version that is greater than or equal to 6.3.
You need to configure a Gradle version for a project to be 5.6.x only or 6.3 or later:
If wrapper.properties is used for the project the Gradle version is saved in the gradle-wrapper.properties file in the gradle directory of your project.
See detailed steps at Configure a Gradle version for a project
documentation page.

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.

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

Gradle: Compile Dependencies

I'm using mongodb with Spring Boot. Recently, my mongodb was upgraded to version 3.0.
I'm using the following Gradle dependencies for Spring:
buildscript {
ext {
springBootVersion = '1.2.6.RELEASE'
}
dependencies {
compile 'org.springframework.boot:spring-boot-starter-data-mongodb'
}
If I look on maven repositories for Gradle: 'org.springframework.boot:spring-boot-starter-data-mongodb:1.2.6.RELEASE', I see the following (http://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-data-mongodb/1.2.6.RELEASE):
The dependencies for the mongo-java-drivers are 2.12.5 under the "Version" column. I was wondering what the "Update" column is there for and how can I use the version of the mongo-java-drivers listed there instead (3.0.4)?
Since I'm using mongo 3.0, I would like to use the 3.0.4 java-drivers instead of 2.12.5 as I need to update my java-drivers to be at least 2.13 before they will work with my mongodb 3.0: http://docs.mongodb.org/manual/release-notes/3.0-scram/#upgrade-drivers
Just add the following dependency to your project dependencies:
compile 'org.mongodb:mongo-java-driver:3.0.4'
This will explicitly set there mongodb Java driver to the newest version and will overrun the transitive dependency version of spring-boot-starter-data-mongodb.
BTW, the "Updates" column means the newest version for a specific Artifact.
You can force the usage of a newer version of a dependency by just explicitly adding the dependency version that you want to use in the pom.xml.
Then Maven will use the explicitly specified version to compile.
FYI, you can exclude a dependency triggered by a direct dependency by using the exclude element.
See this doc to know how maven manages dependencies.
If you are using Gradle, see this page. In fact, you exclude the MongoDB transitive dependency triggered by spring boot and you explicitly add the latest version as a direct dependency.

Resources