"maxHeapSize" not work in jvmArgs, but can work int test blcok, it is a bug or intentional ?

build.gradle

test {
    jvmArgs(
            "-XX:+PrintCommandLineFlags",
            "-XX:MaxHeapSize=8G"
    )
}

console:

---config jvmArgs[-XX:+PrintCommandLineFlags, -XX:MaxHeapSize=8G]

-XX:ConcGCThreads=2 -XX:G1ConcRefinementThreads=8 -XX:GCDrainStackTargetSize=64 -XX:InitialHeapSize=268435456 -XX:MarkStackSize=4194304 -**XX:MaxHeapSize=536870912 -XX:MinHeapSize=6815736 -XX:+PrintCommandLineFlags -XX:ReservedCodeCacheSize=251658240 -XX:+SegmentedCodeCache -XX:+UseCompressedClassPointers -XX:+UseCompressedOops -XX:+UseG1GC 

move MaxHeapSize to test block

test {
   jvmArgs(
           "-XX:+PrintCommandLineFlags",
   )
}
maxHeapSize = "8G"

then output

---config jvmArgs[-XX:+PrintCommandLineFlags]
-XX:ConcGCThreads=2 -XX:G1ConcRefinementThreads=8 -XX:GCDrainStackTargetSize=64 -XX:InitialHeapSize=268435456 -XX:MarkStackSize=4194304 -XX:MaxHeapSize=8589934592 -XX:MinHeapSize=6815736 -XX:+PrintCommandLineFlags -XX:ReservedCodeCacheSize=251658240 -XX:+SegmentedCodeCache -XX:+UseCompressedClassPointers -XX:+UseCompressedOops -XX:+UseG1GC 

why it is not work when use “-XX:MaxHeapSize=8G” in jvmArgs? it is a bug or intentional ?

If you look at the --info output you better see what is happening.
Your -XX:MaxHeapSize=8G comes first and later comes the -Xmx256M which is derived from the default value of “256M” for maxHeapSize.
So later settings wins and your jvm arg is effectively ignored.
This is expected and ok, as you are provided with a dedicated setting for this.