How to pick up JAVA_TOOL_OPTIONS in IntelliJ Gradle build? - gradle

When I run my gradle build using a run configuration, the JAVA_TOOL_OPTIONS that I have set in my ~/.zshenv gets picked up. The result is a successful build. However, when I import the project, reload the project in the gradle tab, or change the build.gradle externally (thus causing it to be reloaded by gradle), the build fails. The failure is due to a failure to resolve plugins. I use JAVA_TOOL_OPTIONS to set "-Djavax.net.ssl.trustStore=/my/cert/location", to set the locations of some certs that are needed for these dependencies.
This is very annoying because one of the core features of IntelliJ gradle integration is auto-building the project.

Use Gradle means to set the JVM options for the Gradle daemon. For example with the Gradle System Properties:
systemProp.javax.net.ssl.trustStore=/my/cert/location

Related

Set Environment variables for "Load Gradle Changes" of intelliJ

I am working on spring boot project which uses gradle script to build and IntelliJ as IDE for development. I want to externalize artifactory username/password from my build.gradle and gradle.properties. One such way is to use environment variables as given here: Build Environment Properties under heading: Setting a project property via an environment variable
I can access variables when I add them to respective task configurations for example build task and it run successfully. But I am facing issue when I make changes to build.gradle and Load Gradle Changes. Getting errors:
Exception is:
org.gradle.api.GradleScriptException: A problem occurred evaluating root project.
Caused by: groovy.lang.MissingPropertyException: Could not get unknown property 'password' for root project
My questions:
Which gradle task is run when I click on Load Gradle Changes.
So that I can add environment variables in this particular task's
configuration.
How can I add these variables only in one place instead of adding them for each task individually.
Configurations:
IntelliJ IDEA 2021.3.1 (Ultimate Edition)
Gradle 7.2
Build time: 2021-08-17 09:59:03 UTC
Revision: a773786b58bb28710e3dc96c4d1a7063628952ad
Kotlin: 1.5.21
Groovy: 3.0.8
Ant: Apache Ant(TM)version 1.10.9 compiled on September 27 2020
JVM: 11.0.2(Oracle Corporation 11.0.2+9)
This works for me. The environment variable defined in OS is respected when I Reload a Gradle project in IDE:
Make sure you have defined the environment variable properly. Double check it in OS terminal. Also do not forget to restart IDE after you changed the OS environment variables for the IDE to pick up the changes.

Intellij Idea: Gradle sync cancelled even if it successful from command line

I am opening a working Gradle project in Idea, but it is failing to sync. In the sync window it says Sync cancelled. I tried changing proxy settings, project SDK, reboot, killing gradle daemon forcefully, but no luck
Solved the problem by changing Gradle JVM from settings.
In Maven project we can set project SDK, and it will be used for Maven build also.
But for Gradle we have to set it differently. Setting project SDK alone doesn't help as it is used only for project by Idea and not for Gradle.
Need to set the Gradle JVM to compatible JVM
Go to Settings
Search for Gradle under Build Tools
Set Gradle JVM to >=1.8

IntelliJ "Deprecated Gradle features" - how to reproduce on command line?

When I reload my Gradle Project in IntelliJ, I get the following output:
Deprecated Gradle features were used in this build, making it incompatible with Gradle 8.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/7.0/userguide/command_line_interface.html#sec:command_line_warnings
However, running gradle commands on the command line, such as tasks or build does not produce this output, even with --warning-mode all.
In order to identify the deprecated features, how can I reproduce what IntelliJ is doing on the command line, or do the equivalent of passing --warning-mode all to Gradle via IntelliJ?
I'm using Gradle 7.0 with the Gradle wrapper, and IntelliJ is set to use the version in gradle-wrapper.properties.
To have IntelliJ run with the warning mode, add it to the gradle.properties file (create the file if it does not exist):
org.gradle.warning.mode=all
I have a new Java Gradle project generated with IntelliJ and run the main from the IDE. When running with this option Gradle explains what's wrong, and indicates the location in the .gradle script IntelliJ is using containing the deprecated property:
Configure project : The JavaExec.main property has been deprecated. This is scheduled to be removed in Gradle 8.0. Please use the
mainClass property instead. See
https://docs.gradle.org/7.4/dsl/org.gradle.api.tasks.JavaExec.html#org.gradle.api.tasks.JavaExec:main
for more details. at
StartApplication_main__1_87e3b1xfpa17mk8z0q8rqeouu$_run_closure1$_closure2$_closure3.doCall(C:\Users\...\AppData\Local\Temp\StartApplication_main__1.gradle:23)
(Run with --stacktrace to get the full stack trace of this
deprecation warning.)
The cause of your deprecation warning may be different (like having jcenter() as suggested by #amitesh-mondal ). Adding the warning property will tell you the cause.
in settings.gradle comment out like
// jcenter() // Warning: this repository is going to shut down soon
This is going to solve the issue

How to have Buildship recognize existing projects in Eclipse Mars

I just converted my Maven project to a gradle project. It was a multi project structure:
master-project
pom.xml
---->project1
-------->pom.xml
---->project2
-------->pom.xml
---->project3
-------->pom.xml
I ran a gradle init on it and have this structure now:
master-project
build.gradle
---->project1
-------->build.gradle
---->project2
-------->build.gradle
---->project3
-------->build.gradle
Everything builds fine, and I have been able to get some things done with that I couldn't figure out how to do with Maven, so that's great. Next step was to integrate that into the IDE since the Maven Dependencies are gone since I have removed the pom.xml files.
However the project isn't recognized as a gradle project - and I am not sure how to change that?
In Eclipse Mars it's still recognized as a Maven build, not gradle....
Thanks in advance.
EDIT: I reimported the projects which enabled the plugin for Eclipse. Now I am having weird behavior.
The build works from the command line, however when attempting the same execution from within Eclipse, it fails trying to copy the file dependencies.
For example:
Couldn't copy dependency jakarta-regexp-1.4.jar
java.nio.file.NoSuchFileException: C:\Users\user.m2\repository\jakarta-regexp\jakarta-regexp\1.4\jakarta-regexp-1.4.jar -> build\jfx\app\lib\jakarta-regexp-1.4.jar
I haven't changed the repo from maven yet - just changed the build scripts. This is running from the master project. So I am confused as to why the script would work from the commandline but not from within eclipse.
EDIT 2: Turns out this behavior is also present when running from the command line when the --daemon flag is set. Is there anyway to run the tasks without the daemon in Buildship? Or perhaps a way to fix this issue when the --daemon flag is enabled?
Thanks.
The issue with the build was that there is a leak in the JDK when bundling the JRE with the native app. This only happens when running with the --daemon flag (which all IDEs user). Therefore until this is fixed you will need to run gradle --stop and then run the clean.
The plug in I am using is no longer running the native task when running with --daemon.

is it possible to do a Maven build using Build Forge?

Is it possible to do a Maven build using Build Forge? Currently we use Build Forge, ClearCase and ClearQuest with Ant scripts; would like to try a Maven build. Not sure if I can I have no test environment so don't want to mess up any thing and still learning all this stuff too
Maven can be invoked from any build automation framework.
Create a buildforge step that invokes your Maven build as follows:
mvn -s /path/to/maven/settings/files/mysettings.xml clean package
Explicitly selecting the settings file is recommended as this enables you customise the Maven configuration for each project.
Project isolation can be further enhanced by ensuring that each project has it's own local repository location (See the "localRepository" parameter in the settings file documentation)

Resources