Uploaded image for project: 'Gradle'
  1. Gradle
  2. GRADLE-2673

Gradle shell script corrupts JAVA_HOME environment variable on Windows/Cygwin

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 2.7-rc-1

      Description

      Hi all,

      I tried to use the JAVA_HOME environment variable inside a build script to exec the xjc tool from the JDK. This worked fine from the Windows command shell, but failed when called from the Cygwin shell. Apparently, the "gradle" shell script (from the Gradle bin folder) modifies the JAVA_HOME environment variable.

      The build file (simplified):

      task printXjcVersion << {
      exec {
      commandLine(
      System.getenv("JAVA_HOME") + "/bin/xjc.exe",
      "-version"
      )
      ignoreExitValue = true
      }
      }

      The output from the Windows shell:

      C:\>gradle -q printXjcVersion
      xjc 2.2.4-2

      The output from the Cygwin shell:

      $ gradle -q printXjcVersion
      FAILURE: Build failed with an exception.

      • What went wrong:
        Execution failed for task ':printXjcVersion'.
        > A problem occurred starting process 'command '/cygdrive/c/Program Files/Java/JDK1.7.0_11/bin/xjc.exe''
      • Try:
        Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

      So the problem is that the cygwin-ified version of JAVA_HOME is useless outside of the starter script. I devised a simple fix for the gradle shell script. The idea is to modify the JAVACMD local variable instead of JAVA_HOME. This works for me. I'm not a shell expert, though.

      The output from the Cygwin shell with my fix:

      $ gradle -q printXjcVersion
      xjc 2.2.4-2

      I'm using Gradle 1.4 on Windows. I attached my simple patch.

      Regards
      Jörg

        Attachments

          Activity

            People

            Assignee:
            Unassigned
            Reporter:
            forums Gradle Forums
            Votes:
            1 Vote for this issue
            Watchers:
            1 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: