Groovy 3 on Java 10 (Module-Info) - java

I'm currently trying to upgrade my Maven project to Java 10 but I'm having issues with the new module system.
One of my systems requires groovy for runtime code execution, so I depend on groovy-all (Version 3.0.0-alpha1).
When compiling however, I receive the following error (which results in a build failure):
module-info.java:[19,20] module not found: groovy.all
IntelliJ doesn't seem to have an issue with groovy.all while editing my module-info file. (However it seems to have issues with Lombok now?)
I recently came across this documentation for gradle which apparently could help fix my issue, however I'm using maven and right now I'm not sure where classpath.asPath comes from.

Related

How to get Eclipse to work properly with Gradle?

I am trying out Eclipse (because of frustrations with apparent version incompatibilities when upgrading another IDE), but it is proving equally problematic. This is a perfectly clean Eclipse installation (windows installer, second variant option), so it's an ootb issue.
(Simplified, theoretically-reproducable version): I downloaded two copies of a basic Java 17 project from Spring Initializr with no dependencies; one as Gradle, one as Maven (tester & tester2 respectively). The Gradle build shows errors where there are none, per the screenshot.
Note that in the one class in the besic, clean SpringBoot application, it sees the package name, the class name, and even the definition of String as being errors. But the same code in the Maven version is fine.
There are further issues that appear to derive from this, but keeping it simpleā€¦
At some point during my testing, some message/error showed up that suggested it was building with Gradle 6.8.3, which I believe would be a problem as that version doesn't support Java 16+. Eclipse is configured to use 7.3.
How do I tell Eclipse to recognise a valid project, so it can be worked with?

Java 11 Methods are not recognised in IntelliJ even after importing them correctly

I have started a new Java 11 Project with the newest Version of the IntelliJ IDEA Community Edition (IntelliJ IDEA 2018.3.5).
Everything seemed to work just fine for a while, but then some MethodCalls from imported modules were not recognised without any obvious reason. I've already tried invalidating the cache, but it did nothing. I'm also using maven 3.6.0 as I stumbled upon a post which suggested that the maven version that comes with said IDEA is not compatible with Java 11.
More specifically I tried using the method Optional.ofNullable() (same with of() or any other method of this class) which IntelliJ even proposed with AutoComplete. After auto-completion however IntelliJ seems to have forgotten it just now knew the method and proclaims: "Cannot find symbol: class ofNullable". The funny thing is: I can even Ctrl-Click Optional to be directed to the class and see that the method is actually there.
I'm at a loss. Has somebody experienced a similar problem?
I have solved this problem as follows for the Spring boot project with the Gradle build tool.
IntelliJ-Idea version should support Java-11.
Bigger scope to narrower scope
(IDE support --> Build tool --> Project setting --> Modules setting --> application run setting)
Add Java-11 SDK in Idea-IDE
Change Gradle JVM to Java-11
Change Project SDK and Language Level to Java-11
Change Module Language Level to Java-11
Change modules SDK to Java-11
Application run configuration to Java-11

Eclipse Lombok annotations not compiled... Why? [duplicate]

This question already has answers here:
Lombok is not generating getter and setter
(25 answers)
Lombok problems with Eclipse Oxygen
(27 answers)
Closed 7 months ago.
I have a problem with my project.
It is an Spring CRUD RestFul API that expose services witch are providing Json datas.
I use JDK-7, Eclipse-Neon and Maven to code, build and the project is deployed into a JBossEAP 6.4 server.
Every thing is working well, the services are responding correctly.
So I decide to add Lombok, to reduce the boiler code and improve the readability of the code. By the way I used Lombok on an another project before and is worked fine.
Here is my problem, after including Lombok :
- When I make an ear using Maven (mvn clean install), everything is going well, the project deploy and work perfectly fine.
- When the project is built by Eclipse, the Lombok annotations (i.e.:#Data, etc) aren't included into the *.class. Consequently the ear deployed by Eclipse work fine BUT all the entity haven't any getter / setter and so on.
I know Eclipse is correctly configured because I haven't any warning associated to Lombok on my code, the outline view of eclipse show me generated methods.
Does anyone have a idea about this kind of problem?
You also must have the lombok plugin installed in Eclipse. (Note that this is something different from lombok being present in the project dependencies; you need both.) Furthermore, the version installed in Eclipse should be the same version that you have in your pom.xml. Otherwise strange compilation issues may occur, like code for some annotations not getting generated in Eclipse but in maven, or vice versa.
Installation instructions for Eclipse can be found here.
Check the "About Eclipse" dialog after the installation and an Eclipse restart. It must contain some text like "Lombok v1.18.3 "Edgy Guinea Pig" is installed.". If that is not the case, the lombok plugin is not installed correctly.
If the installation was not successful, you should try installing lombok to a clean Eclipse installation (even before adding any projects).
Explanation: Eclipse uses its own compiler (different from javac, which maven uses). Therefore, lombok also has to hook into the Eclipse compilation process, and therefore, Eclipse needs that lombok plugin.
Also note that Lombok annotation should never be present in the compiled class file, because the Lombok annotation processor removes them when generating the replacement code.

How to execute gradle plugin with different version of java

I am running into an issue with my gradle build script, build.gradle, for my java project. In this script I need to compile the application with Java 6 in order to comply with the application specifications. However, I am also using a gradle plugin that performs code analysis that needs to be run under a Java 8 JVM. What do I need to do in build.gradle or other gradle settings in order to get this plugin to use a separate Java JVM?
I need to do something like this as gradle tasks fail because the plugin is reporting a Unsupported major.minor version 52.0 Error.
Research
I have done some invesitigation and I did see the following mentioned:
options.fork = true
options.forkOptions.executable = System.getenv('OTHER_JAVA')
Where OTHER_JAVA is an environment variable to the other version of Java. However, I have not been able to get this to work for the plug-in and after some more research, it looks like this may be more limited to compiling with a separate version of java, not executing.
See: How do I tell Gradle to use specific JDK version?
You've pretty much answered your question yourself:
it looks like this may be more limited to compiling with a separate version of java, not executing
Run Gradle under the Java 8 (that would mean specifying your JAVA_HOME as JDK 8), and fork the compiler for your app with Java 6 (as per your research).

Upgrading Groovy 1.7 - 2.1 Incompatability

I am moving from Groovy 1.76 to groovy 2.1 and am having a problem running some Java code.
I have java 7 and Groovy 2.1 all setup on my classpath. Gradle is running and my project can run all its unit tests and execute successfully just as before.
However, I have one java class that loads up one of the groovy classes and executes it (the class can be executed normally in regular gradle/groovy unit tests) and when I try to run this in the new environment it fails with the following exception:
Exception in thread "main" java.lang.NoClassDefFoundError: org/codehaus/groovy/transform/powerassert/ValueRecorder
at com.covestor.glossary.meta.Entity$_Rel__clinit__closure3_closure4.doCall(Entity.groovy:500)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
I have seen in other questions/discussions that some classes were removed from Groovy 1.7, so the general advice seems to be to make sure the classes are re-built against a later version of groovy - but my classes are already being built against the later version (my script that kicks off the java code actually calls gradle clean build first to make sure all groovy classes are properly compiled). There are some jar dependencies as well, but none of them are built from Groovy source (all java jars).
Can anyone suggest what the problem might be? I can't see that I have any code anywhere that is still built against 1.7
The ValueRecorder class is used internally to implement the power assert feature in Groovy. Unfortunately, these classes have been moved to another package from 1.7 to 1.8.
Your error means there is still some 1.7 compiled Groovy code. That's the reason for the NoClassDefFoundError.
I had a similar issue when upgrading, I never created a new GROOVY_HOME to point to the new version of groovy...did you do that and also add $GROOVY_HOME/bin to your path?

Categories