Which file gradle.properties is higher priority? - gradle

I have local and global gradle.properties, the global one is needed to configure the proxy, but it also contains other parameters, wondering what happens if for the same settings you specify different values, which of the files will be in priority or maybe they are How do they merge?
my global gradle.properties
systemProp.http.proxyHost=hostname
systemProp.http.proxyPort=8080
systemProp.http.proxyPassword=password
org.gradle.parallel=false
my local gradle.properties
android.useDeprecatedNdk=true
org.gradle.daemon=true
org.gradle.parallel=true
org.gradle.jvmargs=-Xmx4096M
For example, which org.gradle.parallel will be used?

According to the Gradle properties, the gradle.properties files are applied in the following order:
gradle.properties in project root directory.
gradle.properties in GRADLE_USER_HOME directory.
system properties, e.g. when -Dgradle.user.home is set on the command line.
Because the properties in GRADLE_USER_HOME are applied after the ones in the project root, they override the ones defined in the project. Assuming that with global you mean the one in the GRADLE_USER_HOME directory and local the one in your project root, your value for org.gradle.parallel will be false.

Related

How to configure Gradle module name in InteliJ IDEA

I have project with numerous of submodules located in different directories:
enter image description here
How you can see, the module name of IDEA (in []) differs from directory root. I've tried to modify it though Project Settings, but after gradle sync it returns to initial state.
Is it possible to configure Gradle to set module name according with directory name?
IDE takes the module name from the Gradle configuration, which is by default a project directory name. If you want to change it you can do so by adding the following in the settings.gradle file:
rootProject.name = 'newProjectName'
See also the Naming recommendations from Gradle.

specify gradle properties file as command line argument to gradlew

I am working on a project where there is a different gradle.properties file for each environment. The process seems to be to rename gradle.properties.env (for example) to gradle.properties as required.
I am new to Gradle so possibly this is the wrong approach more broadly, but for now, is there a way to tell ./gradlew to use a specific file as its gradle.properties e.g.
./gradlew --propertiesfile=gradle.properties.env
It is probably better to put the environment-specific property file in the GRADLE_USER_HOME folder (defaulting to $USER_HOME/.gradle). Configurations in this location take priority over the ones in the project folder.
Another option is to supply the individual properties as system properties or environment variables.

Gradle - Can properties be placed in a settings.gradle.kts

Is it possible to place these settings which I currently have in gradle.properties in my settings.gradle.kts file?
org.gradle.parallel=true
org.gradle.caching=true
Thanks
No, this is not possible since gradle.properties configures the JVM that runs the Gradle build and settings.gradle.kts configures the project once the JVM has started and the build starts up. See the documentation on the build environment
In my experience you can't do it.
You can check the gradle properties in the official doc.
The configuration is applied in following order (if an option is configured in multiple locations the last one wins):
gradle.properties in project root directory.
gradle.properties in GRADLE_USER_HOME directory.
system properties, e.g. when -Dgradle.user.home is set on the command line.
These properties are used to sep up the environment for your build:
org.gradle.caching=(true,false)
org.gradle.caching.debug=(true,false)
org.gradle.configureondemand=(true,false)
org.gradle.console=(auto,plain,rich,verbose)
org.gradle.daemon=(true,false)
org.gradle.daemon.idletimeout=(# of idle millis)
org.gradle.debug=(true,false)
org.gradle.java.home=(path to JDK home)
org.gradle.jvmargs=(JVM arguments)
org.gradle.logging.level=(quiet,warn,lifecycle,info,debug)
org.gradle.parallel=(true,false)
org.gradle.warning.mode=(all,none,summary)
org.gradle.workers.max=(max # of worker processes)
org.gradle.priority=(low,normal)
Also you can apply the same rules to settings.gradle and settings.gradle.kts.In the documentation:
Gradle defines a settings file. The settings file is determined by Gradle via a naming convention. The default name for this file is settings.gradle.
The settings file is executed during the initialization phase.
And looking at the Settings class in the API documentation
There is a one-to-one correspondence between a Settings instance and a settings.gradle settings file.
You can check the properties that you can initialize with this file.

Maven3 system.property user.home vs environment variable HOME

There seems to be a problem with the system properties in Maven. It seems that system properties don't correspond to the environment variables.
The situation is that I would like to the change the absolute location of the user-specific settings.xml file, as the Maven document says
If you need to create user-specific settings from scratch, it’s
easiest to copy the global settings from your Maven installation to
your ${user.home}/.m2 directory
which means that the only way to change the absolute location of the user-specific file is to change the user.home property. But it seems that this is not exactly the HOME or HOMEPATH environment variable. In fact, I deleted all the environment variables such as HOME and HOMEPATH, and run mvn using mvn -X just to see the user-specific settings.xml that mvn uses. The result is the following (I am in Windows 7 and I run the command in cmd.exe):
Maven still finds a user.home property, however, I haven't set such a environment variable. To verify this, I then run the set command to see all the environment variables but find nothing about the path d:\Userfiles\xili\ which is used by Maven as the user.home system property. By the way, there is no settings.xml file in this path, because I haven't put any file in this path.
How maven figure out such a path as user.home?
The answer is here!
http://www.timehat.com/javas-user-home-is-wrong-on-windows/
In fact, in Windows, the JVM uses the PATH_TO_DESKTOP_FOLDER_AS_SET_IN_THE_REGISTRY as the reference to determine wheres is the user.home.
user.home is just the parent folder of the above path. That't it, this has nothing to do with the HOME or HOMEPATH enviroment variable.
In the source code of Maven, there should be some code like System.getProperty('user.home').

Set JDK home (javac path) in user's gradle.properties

I need to specify the path to javac in my gradle project. I can do this by adding the following to my build.gradle file:
options.forkOptions.executable = '/home/mj/lib/jdk1.7.0_80/bin/javac'
The problem is that this file is shared in our repository and I do not want the setting to get pushed there. I tried putting it in my local gradle.properties file, but it didn't work. Also setting gradle.java.home does not affect this. I guess it's because gradle uses gradle.java.home for java and not for javac, right? I also (hopelessly) tried setting a gradle.jdk.home which (not surprisingly) didn't work either!
Is there any place outside the project that is included in build.gradle?
In your gradle.properties:
javacPath=/home/mj/lib/jdk1.7.0_80/bin/javac
In your build.gradle
options.forkOptions.executable = project.property('javacPath')
Using a path relative to "java.home" has worked for us. Not elegant, but this does not need another setting. The reason why we need this in the first place is that we build with a JDK that's part of the working copy, not pre-installed with the Jenkins slave. We have no javac/JDK on the slave, just a JRE to run the Jenkins slave. Our gradlew in the working copy points to the JDK next to it.
compileJava {
options.fork = true
options.forkOptions.executable = "${System.properties['java.home']}/../bin/javac"
}
(Note: At Java run time, java.home points to the $JAVA_HOME/jre folder within the JDK. That's one below where the JAVA_HOME environment variable points to.)
It's closing in on the end of 2021 and there's a much simpler approach now. In your project's root directory add the following to your gradle.properties file (add the file, too, if it doesn't exist):
org.gradle.java.home=path/to/jdk

Resources