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.
Related
Screenshot of the error which i have encountered
jdk 11 is installed in my system and added in the environment variable. Maven is also added in the environment variable.
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
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
I have a JavaFX project I am working on using Gradle. What version of java is used when I use the gradle run task from the application plugin?
In IntelliJ I can go into the Gradle settings and change the "Gradle JVM" to any version I want. Is this just the version of java that is used to run the build? Or is this also the version that my application will be run on?
Where does my JAVA_HOME come into this, if at all?
Irrespective of IDEs, Gradle will use whatever language level of the JVM that is running Gradle. Typically whatever the value is for JAVA_HOME.
See Environment variables and Targeting a specific Java version
The new way to do it as of Gradle 6.7 is to use Toolchains for JVM projects
Your IDE should respect whatever Gradle configuration that is configured.
We have a Bamboo build that includes a multi-module Maven build task, for a mixed scala/java project.
The build has worked fine for many months, but started failing today.
Maven successfully builds several modules, then consistently fails on a particular module, with the error:
[ERROR] No compiler is provided in this environment.
Perhaps you are running on a JRE rather than a JDK?
However, a JDK is installed, and this module compiles and builds fine if I log into the bamboo server and run maven manually just for this module.
JAVA_HOME appears to be set correctly on the bamboo server and points to a valid JDK, and I can run javac -version without issue.
No updates have been made to this server recently.
How can we fix this build?
I've found the problem (though not the root cause).
The Maven module that fails is the first one that includes java source files (rather than pure scala), so it is the first module for which Maven tries to invoke javac.
The Maven task in Bamboo specifies a particular named JDK profile.
Checking the Bamboo settings for this JDK, I found that it is set to a path that actually points to a JRE (as indicated by the original error message).
(A JRE is no good because it doesn't include the javac compiler and other build tools).
It is not clear how this path got changed/corrupted (nobody else had access to the server, so it suggests an issue within Bamboo itself) but editing this path to point to the installed JDK again fixes the build.