systemProperties does not do anything


(fx thoorens) #1

this script fails, anything wrong in it?

apply plugin:'groovy'
  test {
        systemProperties 'test': 'test'
        assert 'test'==System.properties['test']
}

using gradle 1.0 on ubuntu, java 6 openjdk

Stacktrace:

> assert 'test'==System.properties['test']
               |
      |
       |
               false
  |
       null
                        [java.runtime.name:OpenJDK Runtime Environment, jna.platform.library.path:/usr/lib:/lib, sun.boot.library.path:/usr/lib/jvm/java-6-openjdk-i386/jre/lib/i386, java.vm.version:20.0-b12, java.vm.vendor:Sun Microsystems Inc., java.vendor.url:http://java.sun.com/, path.separator::, java.vm.name:OpenJDK Client VM, file.encoding.pkg:sun.io, user.country:US, sun.java.launcher:SUN_STANDARD, sun.os.patch.level:unknown, java.vm.specification.name:Java Virtual Machine Specification, user.dir:/home/ubuntu/test, java.runtime.version:1.6.0_24-b24, java.awt.graphicsenv:sun.awt.X11GraphicsEnvironment, java.endorsed.dirs:/usr/lib/jvm/java-6-openjdk-i386/jre/lib/endorsed, os.arch:i386, java.io.tmpdir:/tmp, line.separator:
                        , org.gradle.appname:gradle, java.vm.specification.vendor:Sun Microsystems Inc., os.name:Linux, jna.boot.library.path:/home/ubuntu/.gradle/jna, sun.jnu.encoding:UTF-8, java.library.path:/usr/lib/jvm/java-6-openjdk-i386/jre/lib/i386/client:/usr/lib/jvm/java-6-openjdk-i386/jre/lib/i386:/usr/lib/jvm/java-6-openjdk-i386/jre/../lib/i386:/usr/java/packages/lib/i386:/usr/lib/i386-linux-gnu/jni:/lib/i386-linux-gnu:/usr/lib/i386-linux-gnu:/usr/lib/jni:/lib:/usr/lib, java.class.version:50.0, java.specification.name:Java Platform API Specification, sun.management.compiler:HotSpot Client Compiler, os.version:3.2.0-27-generic, user.home:/home/ubuntu, user.timezone:Europe/Paris, java.awt.printerjob:sun.print.PSPrinterJob, java.specification.version:1.6, file.encoding:UTF-8, user.name:ubuntu, java.class.path:/home/ubuntu/Applications/gradle-1.0/lib/gradle-launcher-1.0.jar, java.vm.specification.version:1.0, sun.arch.data.model:32, sun.java.command:org.gradle.launcher.GradleMain test, java.home:/usr/lib/jvm/java-6-openjdk-i386/jre, java.specification.vendor:Sun Microsystems Inc., user.language:en, java.vm.info:mixed mode, sharing, java.version:1.6.0_24, java.ext.dirs:/usr/lib/jvm/java-6-openjdk-i386/jre/lib/ext:/usr/java/packages/lib/ext, sun.boot.class.path:/usr/lib/jvm/java-6-openjdk-i386/jre/lib/resources.jar:/usr/lib/jvm/java-6-openjdk-i386/jre/lib/rt.jar:/usr/lib/jvm/java-6-openjdk-i386/jre/lib/sunrsasign.jar:/usr/lib/jvm/java-6-openjdk-i386/jre/lib/jsse.jar:/usr/lib/jvm/java-6-openjdk-i386/jre/lib/jce.jar:/usr/lib/jvm/java-6-openjdk-i386/jre/lib/charsets.jar:/usr/lib/jvm/java-6-openjdk-i386/jre/lib/netx.jar:/usr/lib/jvm/java-6-openjdk-i386/jre/lib/plugin.jar:/usr/lib/jvm/java-6-openjdk-i386/jre/lib/rhino.jar:/usr/lib/jvm/java-6-openjdk-i386/jre/lib/modules/jdk.boot.jar:/usr/lib/jvm/java-6-openjdk-i386/jre/classes, java.vendor:Sun Microsystems Inc., file.separator:/, java.vendor.url.bug:http://java.sun.com/cgi-bin/bugreport.cgi, sun.io.unicode.encoding:UnicodeLittle, sun.cpu.endian:little, sun.desktop:gnome, sun.cpu.isalist:]

(Luke Daley) #2

You are setting the system properties for the forked JVM process that the tests run in, not the JVM the build is running in.


(fx thoorens) #3

ok, got it thanks. so if i use

systemProp.test=test

in gradle.properties, that property will be available for gradle jvm process but not for the forked test process, which means that i have to bind it again like

test {
        systemProperties 'test': System.properties['test']
}

Still find it weird, but it’s logical


(René Groeschke) #4

Hey, in another thread (http://forums.gradle.org/gradle/topics/passing_system_properties_to_test_task) I provided an example of how to implement reusage of system properties with a custom plugin. maybe that helps.

cheers, René


(fx thoorens) #5

yes sounds something like that! thanks for the hint!