Home > Software engineering >  How to set Xmx and Xms properly in Gradle
How to set Xmx and Xms properly in Gradle

Time:12-05

I'm trying to fix the heap size memory using -Xmx50M in build.gradle file, it doesn't work, the memory size always goes beyond 50M.

Details :

My build.gradle

   plugins {
    id 'java'
    id 'application'
    id 'org.openjfx.javafxplugin' version '0.0.10'
}

group 'com.karrty'

repositories {
    mavenCentral()
}

ext {
    junitVersion = '5.7.1'
}

sourceCompatibility = '17'
targetCompatibility = '17'

tasks.withType(JavaCompile) {
    options.encoding = 'UTF-8'
}

application {
    mainModule = 'com.karrty.karrtyversion1'
    mainClass  = 'com.karrty.karrtyversion1.Principle.main'
}

javafx {
    version = '16'
    modules = ['javafx.controls', 'javafx.fxml']
}

dependencies {
    implementation('org.controlsfx:controlsfx:11.1.0')
}

run {

    jvmArgs = [
         
            "-Xms50m",
            "-Xmx50m"
    ]
}

Screen shot of the issue

enter image description here

as you can see, the app has located 500MB in memory and using almost 250MB of it, even tho I specified the heap memory size to be 50MB .

CodePudding user response:

Am not 100% sure , but i think you should be using gradle.properties to set -Xmx50M . You can check the official docs to make sure . gradle.properties should look like this

org.gradle.jvmargs=-Xmx512m "-XX:MaxMetaspaceSize=256m"

This is the default and you can change based on what you need to do .

CodePudding user response:

For some reason using the short VM arguments Xms50m and Xmx50m is not working with gradle, but the full expressions -XX:MaxHeapSize=50m and -XX:InitialHeapSize=50 are working, if you also have the same issue , just replace those short expressions with their full expressions and it will work.

  • Related