Currently, I cannot get this project to run, somehow the Gradle cannot find the Lombok module. I'm using
lombok version 1.18.12
OpenJDK 11.0.8
Gradle 6.4
Based on this github issue, then the problem should be solved at this version, but it doesn't work for me.
Here is the error
> Task :Model-library:compileJava FAILED
/home/dauto98/path..to..project/src/main/java/module-info.java:2: error: module not found: lombok
requires static lombok;
below is my gradle.build.kts file
plugins {
java
`java-library`
}
group = "org.example"
version = "1.0-SNAPSHOT"
repositories {
mavenCentral()
}
dependencies {
testImplementation("junit", "junit", "4.12")
compileOnly("org.projectlombok:lombok:1.18.12")
annotationProcessor("org.projectlombok:lombok:1.18.12")
testCompileOnly("org.projectlombok:lombok:1.18.12")
testAnnotationProcessor("org.projectlombok:lombok:1.18.12")
}
configure<JavaPluginConvention> {
sourceCompatibility = JavaVersion.VERSION_11
}
my module-info.java file
module my.module.main {
requires static lombok;
}
After a while, I found out that the problem is I didn't turn on module path inference explicitly in the Gradle build file as stated in here
Add this to the gradle.build.kts file:
plugins.withType<JavaPlugin>().configureEach {
configure<JavaPluginExtension> {
modularity.inferModulePath.set(true)
}
}
Related
I had changed my project from maven to gradle. but I had error with this command
./gradlew build --scan
for project that has lombok in it.
I've tried all method from online an it is useless. The build.gradle file is in kotlin language
Here is the build.gradle.kts
/*
* This file was generated by the Gradle 'init' task.
*/
plugins {
java
`maven-publish`
}
repositories {
mavenLocal()
maven {
url = uri("https://repo.maven.apache.org/maven2/")
}
}
dependencies {
implementation("org.springframework.boot:spring-boot-starter-data-jpa:2.3.9.RELEASE")
implementation("org.springframework.boot:spring-boot-starter-validation:2.3.9.RELEASE")
implementation("org.springframework.boot:spring-boot-starter-actuator:2.3.9.RELEASE")
implementation("org.springframework.boot:spring-boot-starter-web:2.3.9.RELEASE")
implementation("org.springframework.cloud:spring-cloud-starter-config:2.2.0.RELEASE")
implementation("org.springframework.cloud:spring-cloud-starter-sleuth:2.2.0.RELEASE")
implementation("org.springframework.cloud:spring-cloud-sleuth-zipkin:2.2.0.RELEASE")
implementation("org.springframework.cloud:spring-cloud-starter-openfeign:2.2.0.RELEASE")
implementation("org.springframework.cloud:spring-cloud-starter-netflix-eureka-client:2.2.0.RELEASE")
implementation("io.springfox:springfox-swagger2:2.9.2")
implementation("io.springfox:springfox-swagger-ui:2.9.2")
implementation("org.projectlombok:lombok:1.18.18")
runtimeOnly("mysql:mysql-connector-java:8.0.23")
testImplementation("org.springframework.boot:spring-boot-starter-test:2.3.9.RELEASE")
}
group = "com.bank"
version = "0.0.1-SNAPSHOT"
description = "transaction"
java.sourceCompatibility = JavaVersion.VERSION_1_8
publishing {
publications.create<MavenPublication>("maven") {
from(components["java"])
}
}
tasks.withType<JavaCompile>() {
options.encoding = "UTF-8"
}
It seems to me. that you have to apply a plugin to your build script, as it's said in the lombok docs
Something like this:
plugins {
...
id "io.freefair.lombok" version "6.4.2"
}
Or you have to provide annotation processor dependency, but I think that the plugin suits better.
So I've used the latest version instead of lombok 1.18.18
compileOnly("org.projectlombok:lombok:1.18.22")
annotationProcessor("org.projectlombok:lombok:1.18.22")
testCompileOnly("org.projectlombok:lombok:1.18.22")
testAnnotationProcessor("org.projectlombok:lombok:1.18.22")
I am using gradle 7.3.1 in Intellij 2021.3 to build a JavaFX application. And I need external libraries dependency for the backend part.
This is the complete build.gradle script that is pre-built by the idea:
plugins {
id 'java'
id 'application'
id 'org.openjfx.javafxplugin' version '0.0.10'
id 'org.beryx.jlink' version '2.24.1'
}
group 'com.github.zukarusan'
version '1.0-SNAPSHOT'
repositories {
mavenCentral()
}
ext {
junitVersion = '5.8.1'
}
sourceCompatibility = '11'
targetCompatibility = '11'
tasks.withType(JavaCompile) {
options.encoding = 'UTF-8'
}
application {
mainModule = 'com.github.zukarusan.app'
mainClass = 'com.github.zukarusan.app.MainApplication'
}
javafx {
version = '11.0.2'
modules = ['javafx.controls', 'javafx.fxml']
}
dependencies {
implementation('org.controlsfx:controlsfx:11.1.0')
implementation('com.dlsc.formsfx:formsfx-core:11.3.2') {
exclude(group: 'org.openjfx')
}
implementation('org.kordamp.ikonli:ikonli-javafx:12.2.0')
implementation('org.kordamp.bootstrapfx:bootstrapfx-core:0.4.0')
implementation('com.github.wendykierp:JTransforms:3.1') // THIS IS THE EXTERNAL LIBRARY I ADDED
testImplementation("org.junit.jupiter:junit-jupiter-api:${junitVersion}")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:${junitVersion}")
}
test {
useJUnitPlatform()
}
jlink {
imageZip = project.file("${buildDir}/distributions/app-${javafx.platform.classifier}.zip")
options = ['--strip-debug', '--compress', '2', '--no-header-files', '--no-man-pages']
launcher {
name = 'app'
}
}
jlinkZip {
group = 'distribution'
}
and then I updated module-info.java:
module com.github.zukarusan.app {
requires javafx.controls;
requires javafx.fxml;
requires org.controlsfx.controls;
requires com.dlsc.formsfx;
requires org.kordamp.ikonli.javafx;
requires org.kordamp.bootstrapfx.core;
requires java.desktop;
requires JTransforms; // UPDATED
exports com.github.zukarusan.app.controller;
exports com.github.zukarusan.app.model;
exports com.github.zukarusan.app;
opens com.github.zukarusan.app.controller to javafx.fxml;
}
Before I updated the module-info
, the application launches just fine and shows a javafx window application.
But, after I updated that, java.lang.FindException is thrown. resulting the following error:
> Task :MainApplication.main() FAILED
Error occurred during initialization of boot layer
java.lang.module.FindException: Module JTransforms not found, required by com.github.zukarusan.app
Do I have to download manually the modules? or any steps that I miss?
Please enlighten me. :'(
Guided by #jewelsea in the comment, I have finally resolved this issue.
After several days, I figured out that my imported libraries in modular java project are treated as an unnamed module (correct me if I am wrong). As I understood so far, libraries like JTransforms may belong to traditional libraries that do not cover the modularity feature like in Java 9. This means that the jar library does not have Automatic-Module-Name at the very least in its manifest metadata. See the gradle documentation.
That is to say, I will have another approach using a grade plugin extra-java-module-info and found a somewhat similar case in this post.
Ultimately, I add the following script in build.gradle
plugins {
... // other plugins
id 'de.jjohannes.extra-java-module-info' version '0.11'
}
extraJavaModuleInfo {
module("JTransforms-3.1.jar", "JTransforms", "3.1") {
exports("org.jtransforms")
}
}
Then hit that sync button. That's all!
Cheers! Thanks again to #jewelsea.
Overview:
I am trying to upgrade Java and Gradle version in my project as follows:
java from 8 to 11
Gradle from 5 to 6
My project runs with no issues on the old versions but when runs on Java 11 and Gradle 6 it complains about fireBugs plugin and raises the following exception:
> Plugin with id 'findbugs' not found.
Snippet of gradle file:
buildscript {
ext {
SampleProjectVersion = '1.3.4'
}
repositories {
mavenLocal()
maven {
url1
}
}
dependencies {
classpath(sample lib 1)
classpath(sample lib 2)
}
apply plugin: 'findbugs'
...
I would appreciate if you could share your thoughts with me as I couldn't find any proper solution for that.
From the Gradle web site (Upgrading your build from Gradle 5.x to 6.0):
The FindBugs plugin has been removed
The deprecated FindBugs plugin has been removed. As an alternative,
you can use the SpotBugs plugin from the Gradle Plugin Portal.
https://docs.gradle.org/current/userguide/upgrading_version_5.html
You can use the SpotBugs plugin. Try my snippet of gradle file
buildscript {
ext {
SampleProjectVersion = '1.3.4'
}
repositories {
mavenLocal()
maven {
url1
}
}
dependencies {
classpath(sample lib 1)
classpath(sample lib 2)
classpath "gradle.plugin.com.github.spotbugs:spotbugs-gradle-plugin:2.0.0"
}
apply plugin: "com.github.spotbugs"
tasks.withType(com.github.spotbugs.SpotBugsTask) {
spotbugsMain.enabled = true
spotbugsTest.enabled = true
reports {
xml.enabled = false
html.enabled = true
}
}
...
I have created Spring Boot project with
SDK 11. Java Version 11.0.3
Kotlin as language
Gradle
I'm following this Tutorial:
https://scotch.io/#grahamcox82/how-to-build-a-simple-rest-api-with-kotlin-and-spring-boot
I'm trying to
import java.time.Instant
in my Kotlin data class
And have an error
Unresolved reference: java
build.gradle.kts file:
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins {
id("org.springframework.boot") version "2.1.6.RELEASE"
id("io.spring.dependency-management") version "1.0.7.RELEASE"
kotlin("jvm") version "1.2.71"
kotlin("plugin.spring") version "1.2.71"
}
group = "com.smight"
version = "0.0.1"
java.sourceCompatibility = JavaVersion.VERSION_1_8
val developmentOnly by configurations.creating
configurations {
runtimeClasspath {
extendsFrom(developmentOnly)
}
}
repositories {
mavenCentral()
}
dependencies {
implementation("org.springframework.boot:spring-boot-starter-data-mongodb")
implementation("org.springframework.boot:spring-boot-starter-webflux")
implementation("com.fasterxml.jackson.module:jackson-module-kotlin")
implementation("org.jetbrains.kotlin:kotlin-reflect")
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
developmentOnly("org.springframework.boot:spring-boot-devtools")
testImplementation("org.springframework.boot:spring-boot-starter-test")
testImplementation("io.projectreactor:reactor-test")
}
tasks.withType<KotlinCompile> {
kotlinOptions {
freeCompilerArgs = listOf("-Xjsr305=strict")
jvmTarget = "1.8"
}
}
Maybe I should install java library? How can I check this?
Can anyone help please?
According to some research, this error can appear in this conditions :
You created a Kotlin2Js project instead of Kotlin JVM (source), try to recreate your project by selecting the right project type
or
You are using a Kotlin version that does not support JDK 11 (source), install JDK 8 instead and reconfigure your JAVA_HOME environment variable
It may as well be an error in your build.gradle file, copy/paste it in your question if the solutions above doesn't work
To get a more specific error you should first clean the autogenerated files
$ ./gradlew clean
In a modularized Spring project using Kotlin DSL the unresolved reference error could occur because the submodules are bootable.
build.gradle.kts (Project)
...
subprojects {
...
tasks.getByName<BootJar>("bootJar") {
enabled = false
}
tasks.getByName<Jar>("jar") {
enabled = true
}
}
GL
The problem was that JDK was not correct found from IntelliJ
I solved the problem so:
File -> Project Structure -> SDKs -> "+"
Find the path to your SDK where it is installed
New Project
Copy/Paste
Rebuild
I am trying to use Google checkstyle configuration (https://github.com/checkstyle/checkstyle/blob/master/src/main/resources/google_checks.xml) but I am constantly getting an error on gradle check:
Unable to create a Checker: cannot initialize module TreeWalker - Unable to instantiate EmptyCatchBlock
I used Gradle to build the project. Below is my gradle.build.
apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'checkstyle'
sourceCompatibility = 1.8
version = '1.0'
checkstyle {
toolVersion = "6.3"
}
task "create-dirs" << {
sourceSets*.java.srcDirs*.each { it.mkdirs() }
sourceSets*.resources.srcDirs*.each { it.mkdirs() }
}
jar {
manifest {
attributes 'Implementation-Title': 'xyz',
'Implementation-Version': 0.01
}
}
repositories {
mavenCentral()
}
dependencies {
compile (
['org.apache.logging.log4j:log4j-api:2.2'],
['org.apache.logging.log4j:log4j-core:2.2']
)
testCompile(
['junit:junit:4.11'],
['org.mockito:mockito-core:1.+']
)
}
test {
systemProperties 'property': 'value'
}
uploadArchives {
repositories {
flatDir {
dirs 'repos'
}
}
}
Also, when I try to add XML config file to Checkstyle plugin in IDEA I get similar error but with a stack trace:
org.infernus.idea.checkstyle.exception.CheckStylePluginException: <html><b>The CheckStyle rules file could not be loaded.</b><br>cannot initialize module TreeWalker - Unable to instantiate EmptyCatchBlock</html>
at org.infernus.idea.checkstyle.checker.CheckerFactory.blacklistAndShowMessage(CheckerFactory.java:234)
at org.infernus.idea.checkstyle.checker.CheckerFactory.createChecker(CheckerFactory.java:188)
at org.infernus.idea.checkstyle.checker.CheckerFactory.getOrCreateCachedChecker(CheckerFactory.java:98)
at org.infernus.idea.checkstyle.checker.CheckerFactory.getChecker(CheckerFactory.java:73)
at org.infernus.idea.checkstyle.checker.CheckerFactory.getChecker(CheckerFactory.java:41)
I cannot figure out what am I doing wrong. Any help would be appreciated.
Gradle version: 2.2
You can add this configuration into your build.gradle file:
configurations {
checkstyleOverride
}
dependencies {
checkstyleOverride('com.puppycrawl.tools:checkstyle:6.11.2')
}
tasks.withType(Checkstyle) {
checkstyleClasspath = project.configurations.checkstyleOverride
}
Enjoy!
The problem lies in the fact that com.puppycrawl.tools.checkstyle.checks.blocks.EmptyCatchBlockCheck was indeed added to checkstyle but for version 6.4-SNAPSHOT. As it can be seen in checkstyle repository (pom.xml history) version 6.4-SNAPSHOT was introduced on the 02.02.2015 and EmptyCatchBlockCheck class was created on 18.02.2015.
Gradle still uses version 6.3 as in the following log extract:
:checkstyleMain
Download https://repo1.maven.org/maven2/com/puppycrawl/tools/checkstyle/6.3/checkstyle-6.3.pom
So there's simply no class You'd like to use.
According to the docs checkstyle classpath can be specified with checkstyleClasspath property - you can try to set it up manually.
I've also prepared a demo with 6.4-SNAPSHOT version, it can be found here. Checkstyle jar was built with mvn clean package with source taken from this repo.
Here is an approach that works with the (currently) latest versions of Gradle & Checkstyle (Gradle 6.1.1 & Checkstyle 8.29):
plugins {
id 'java'
id 'checkstyle'
}
configurations {
checkstyleConfig
}
dependencies {
checkstyleConfig("com.puppycrawl.tools:checkstyle:8.29") { transitive = false }
}
checkstyle {
toolVersion '8.29'
config = resources.text.fromArchiveEntry(configurations.checkstyleConfig, 'google_checks.xml')
}
Note that the Checkstyle dependency excludes transitive dependencies, otherwise the resources.text.fromArchiveEntry will fail since multiple JAR files will be present, and it will be unable to select a single one.