@@ -10,6 +10,7 @@ import org.gradle.api.tasks.InputFile
1010import org.gradle.api.tasks.InputFiles
1111import org.gradle.api.tasks.JavaExec
1212import org.gradle.api.tasks.Optional
13+ import org.gradle.api.tasks.OutputDirectory
1314import org.gradle.api.tasks.TaskInstantiationException
1415import org.gradle.internal.FileUtils
1516import org.gradle.process.ExecResult
@@ -55,6 +56,9 @@ class JRubyExec extends JavaExec {
5556 @Input
5657 String jrubyVersion
5758
59+ @OutputDirectory
60+ File gemWorkDir
61+
5862 JRubyExec () {
5963 super ()
6064 super . setMain ' org.jruby.Main'
@@ -86,6 +90,27 @@ class JRubyExec extends JavaExec {
8690 }
8791 }
8892
93+ /* * Sets the working directory used by the task for installing GEMs.
94+ * By default every task will use its own private directory, so that tasks
95+ * can be run in isolation avoiding potential clashes between different versions
96+ * of the same GEM. If the user requires multiple tasks to share the same GEM area
97+ * then this configuration property can be used to to provide such a folder..
98+ *
99+ * @param fName Path to script
100+ */
101+ void setGemWorkDir (Object fName ) {
102+ switch (fName) {
103+ case File :
104+ gemWorkDir= fName
105+ break
106+ case String :
107+ gemWorkDir = new File (fName)
108+ break
109+ default :
110+ gemWorkDir = new File (fName. toString())
111+ }
112+ }
113+
89114 /* * Returns a list of script arguments
90115 */
91116 List<String > scriptArgs () {
@@ -148,17 +173,19 @@ class JRubyExec extends JavaExec {
148173
149174 GemUtils.OverwriteAction overwrite = project. gradle. startParameter. refreshDependencies ? GemUtils.OverwriteAction . OVERWRITE : GemUtils.OverwriteAction . SKIP
150175 def jrubyCompletePath = project. configurations. getByName(jrubyConfigurationName)
151- File gemDir = tmpGemDir()
152- gemDir. mkdirs()
153- environment ' GEM_HOME' : gemDir,
176+ if (gemWorkDir == null ) {
177+ gemWorkDir = tmpGemDir()
178+ }
179+ gemWorkDir. mkdirs()
180+ environment ' GEM_HOME' : gemWorkDir,
154181 ' PATH' : getComputedPATH(System . env. PATH )
155182
156183 if (configuration != null ) {
157184 GemUtils . extractGems(
158185 project,
159186 jrubyCompletePath,
160187 project. configurations. getByName(configuration),
161- gemDir ,
188+ gemWorkDir ,
162189 overwrite
163190 )
164191 }
0 commit comments