I am using the latest version of the Community Edition of IntelliJ Idea ( 2021.2 ) with the Groovy plugin ( 212.4746.92 ) on a Windows 10 box.
I created a very simple Groovy class:
class HWClass {
static void main(String[] args) {
// Using a simple println statement to print output to the console
println('Hello World');
}
}
When I try and run the Groovy class I get :
java.util.concurrent.ExecutionException: java.lang.RuntimeException:
java.lang.reflect.InvocationTargetException
I have verified my project setup many times ...I have my Platform Settings SDK set to OpenJDK 12 and my Global Libraries references my Groovy 3.0.8 installation. Note that this is a new release of IntelliJ Idea I am using ( 2021.2 ) ...I am aware of a known bug in this release of IntelliJ ( https://youtrack.jetbrains.com/issue/IDEA-275043 ) with Groovy Scripts but am unaware of any issues with Groovy classes... any thoughts ?
Related
I am using intellij & Lombok & I have annotation processor set to enabled.
IntelliJ IDEA 2020.2 (Community Edition)
Build #IC-202.6397.94, built on July 27, 2020
Runtime version: 11.0.7+10-b944.20 amd64
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o.
Linux XXXX
GC: ParNew, ConcurrentMarkSweep
Memory: XXXXM
Cores: XX
Non-Bundled Plugins: color.scheme.Gruvbox, Lombook Plugin, org.intellij.scala
Current Desktop: KDE
And using Lobmok: 0.30-EAP
When I create a class like so:
#Builder
#Getter
public class Stub {
private final int f1;
private final long f2;
}
Or if I add a field to an existing class Intellij Complains that: Variable 'f1' might not have been initialized.
If I restart Intellij the error goes away.
Build/Recompiling the class doesn't help
Maven reload proejct doesn't help
Build/Build the project doesn't help
IntelliJ IDEA 2020.2 has a known issue affecting Lombok plug-in. It's fixed in 2020.2.1 release. Please update.
I am facing hard time in the live reload using Spring-Boot-Devtools. Every time I update my controller class, the spring couldn't find the dependencies which are injected using constructor injection.
Suppose I am having this class
class MyController{
private MyService myService;
public MyController(MyService myService){
this.myService= myService;
}
//controller methods
}
Changes to any of the controller methods or the MyService's methods would result in some error like: constructor in com.example.MyController required a bean of type 'com.example.MyService' that could not be found
Whereas if I run the same code on the Eclipse, the live reload works fine.
IntelliJ IDEA 2019.1.2 (Ultimate Edition)
JRE: 1.8.0_202-release-1483-b49 x86_64
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
macOS 10.13.6
I am trying to run the simple 'getting-started'-type gradle project with quarkus and my unit test fails everytime with this error
Caused by: io.quarkus.bootstrap.BootstrapException: Failed to locate project pom.xml for C:\Users\myuser\IdeaProjects\myproj\build\classes\java\main
Followed instructions here https://quarkus.io/guides/gradle-tooling
Any suggestions or thoughts on what is going on?
Gradle version details
Gradle 5.4
Build time: 2019-04-16 02:44:16 UTC
Revision: a4f3f91a30d4e36d82cc7592c4a0726df52aba0d
Kotlin: 1.3.21
Groovy: 2.5.4
Ant: Apache Ant(TM) version 1.9.13 compiled on July 10 2018
JVM: 11.0.2 (Oracle Corporation 11.0.2+9)
OS: Windows 10 10.0 amd64
btw. the problem is still open (current version 0.19.1) and issue (2307) is still unresolved.
The reason is that #QuarkusTest points to the QuarkusTestExtension, which in BootstrapClassLoaderFactory.newDeploymentClassLoader attempts to resolve local project with Maven.
We have options:
wait for official solution (see issue)
write own extension overriding BootstrapClassLoaderFactory to "understand" gradle project structure
apply a workaround (for time being), i.e. generate pom.xml from gradle build
Workaround
in build.grade:
plugins {
id 'java'
id 'io.quarkus' version '0.19.1'
// ...
id 'maven-publish'
}
// ...
publishing {
publications {
mavenJava(MavenPublication) {
from components.java
// augment your pom here if necessary
}
}
}
// ...
task createPom(type: Copy) {
description 'This is workaround to generate pom.xml, needed for #QuarkusTest tests.'
dependsOn('generatePomFileForMavenJavaPublication')
from "$buildDir/publications/mavenJava/pom-default.xml"
into '.'
rename('pom-default.xml', 'pom.xml')
}
Note:
use 'maven-publish', not obsolete 'maven' plugin.
do not forget to apply ./gradlew createPom on dependencies changes
I have a simple build script (shorted for clarity) which uses Guava as a dependency
group 'test'
version '0.1.0'
apply plugin: 'java'
apply plugin: 'application'
sourceCompatibility = 1.8
targetCompatibility = 1.8
mainClassName = 'Test'
repositories {mavenCentral()}
task wrapper(type: Wrapper) {gradleVersion = '3.5'}
dependencies {compile 'com.google.guava:guava:21.0'}
When running this code:
public class Test {
public static void main(String[] args) {
LoadingCache<Long, String> applicantCache = CacheBuilder.newBuilder()
.maximumSize(30000)
.expireAfterAccess(31, TimeUnit.DAYS)
.build(new CacheLoader<Long, String>() {
#Override
public String load(Long key) {
return "";
}
});
}
}
I get this error:
java.lang.NoClassDefFoundError: com/google/common/cache/CacheLoader
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
at java.lang.Class.privateGetMethodRecursive(Class.java:3048)
at java.lang.Class.getMethod0(Class.java:3018)
at java.lang.Class.getMethod(Class.java:1784)
at sun.launcher.LauncherHelper.validateMainClass(LauncherHelper.java:544)
at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:526)
Caused by: java.lang.ClassNotFoundException: com.google.common.cache.CacheLoader
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 7 more
Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main"
When downgrading the Gradle Wrapper version to 3.3 the problem is fixed but, I need version 3.5 for something else that is not feasible in version 3.3. As far as I can understand there is some dependency conflict between this version of Gradle and Guava but according to this post - it is not possible.
I know the jar is in place + using gradle dependencyInsight --dependency com.google.guava shows that the dependency exists:
:dependencyInsight
com.google.guava:guava:21.0
\--- compile
Thanks for any help
EDIT:
After testing on other computers it seems the problem only occurs when I update the wrapper task, execute it and then refresh the gradle project by clicking on the Refresh all Gradle projects button (see attached image). When running the executing distribution script every thing works fine - so it only happens in Intellij. I'm guessing I'm missing something in how Gradle Wrapper works or when to execute it...
EDIT
Tested on Gradle version 3.4 and the problem occurres.
if anyone else encounters similar issues the answer is here.
A bug in my Intellij version (2016.2.5) caused compile scoped dependencies to transform into provided scoped dependencies by Intellij. This, in turn, makes dependencies to appear only in Intellij's compile classpath but not in it's runtime classpath. That's why when running the ./gradlew run command the issue could not be reproduced as there was no issue on Gradle's part.
Upgrading the Intellij version (2017.1) solved the issue.
When using Log4j2 in Intellij for a groovy/gradle project, log shows up red as if the injection is not working. Gradle runs and builds but every file in IntelliJ shows errors which is annoying.
dependencies
compile 'org.codehaus.groovy:groovy-all:2.4.4'
compile 'org.apache.logging.log4j:log4j-api:2.5'
compile 'org.apache.logging.log4j:log4j-core:2.5'
Source
import groovy.util.logging.Log4j2
#Log4j2
class TestLog4j2 {
public static void log(String message) {
log.error(message)
log from log.error is displayed in red and displays error, cannot resolve symbol 'log'
The log4j2.xml file is in the classpath and works.
#Log4j and even #Slf4j both work
Using IntelliJ 15.03 Build IU-143.1821
Project is using Groovy 2.4.4 and Gradle 2.3
Thoughts anyone?
I was getting this error when using groovy's #Log4j2 annotation.
The solution was to exclude the following module in gradle:
configurations.all {
exclude module: 'log4j-to-slf4j'
}