[GRADLE-2664] Respect custom gradle user home defined via env variable during tooling api processing Created: 30/Jan/13  Updated: 10/Feb/17  Resolved: 10/Feb/17

Status: Resolved
Project: Gradle
Affects Version/s: 1.4
Fix Version/s: None

Type: Bug
Reporter: Denis Zhdanov Assignee: Unassigned
Resolution: Won't Fix Votes: 1


 Description   

Gradle reference mentions that it's possible to configure custom gradle home to use via system env variable. However, gradle tooling api doesn't follow that rule all the time. Consider the following simple example:

package org.jetbrains.plugins.gradle;

import org.gradle.tooling.*;
import org.gradle.tooling.internal.consumer.DefaultGradleConnector;
import org.gradle.tooling.model.idea.*;

import java.io.File;
import java.util.Date;
import java.util.concurrent.TimeUnit;

/**
 * @author Denis Zhdanov
 * @since 12/8/11 5:07 PM
 */
public class GradleStartClass {

  private static final String GRADLE_TO_USE       = "/home/denis/dev/gradle/gradle-1.4-rc-2";
  private static final String GRADLE_PROJECT_PATH = "/home/denis/dev/gradle/gradle-1.3/samples/java/quickstart";

  public static void main(String[] args) throws InterruptedException {
    System.out.println("GRADLE_USER_HOME=" + System.getenv("GRADLE_USER_HOME"));
    //showDependencies(true);
    showDependencies(false);
  }


  private static void showDependencies(boolean useWrapper) {
    GradleConnector connector = GradleConnector.newConnector();
    if (!useWrapper) {
      connector.useInstallation(new File(GRADLE_TO_USE));
    }
    ((DefaultGradleConnector)connector).daemonMaxIdleTime(10000, TimeUnit.MILLISECONDS);
    connector.forProjectDirectory(new File(GRADLE_PROJECT_PATH));
    ProjectConnection connection = connector.connect();
    ModelBuilder<? extends IdeaProject> modelBuilder = connection.model(IdeaProject.class);
    System.out.println(new Date() + ": Starting project resolve");
    IdeaProject project = modelBuilder.get();
    System.out.println(new Date() + ": Project resolve is complete");
    System.out.println("-----------------> Listing modules <----------------");
    for (IdeaModule module : project.getModules()) {
      System.out.printf("    -----------------> Module %s <----------------%n", module.getName());
      for (IdeaDependency dependency : module.getDependencies()) {
        System.out.printf("Dependency: %s, scope: %s%n", dependency, dependency.getScope());
      }
    }
    System.out.println("-----------------> Finishing <----------------");
  }
}

The main idea is to do the following:

  1. Print out current GRADLE_USER_HOME env variable value (ensure that it's set);
  2. Build project structure via tooling api;

The output is below:

GRADLE_USER_HOME=/home/denis/Downloads/gradle-repo
14:34:22.028 [main] DEBUG org.gradle.tooling.GradleConnector - Connecting from tooling API consumer version 1.4-rc-2
Wed Jan 30 14:34:22 MSK 2013: Starting project resolve
14:34:22.099 [Connection worker] DEBUG o.g.t.i.c.l.DefaultToolingImplementationLoader - Using tooling provider from Gradle installation '/home/denis/dev/gradle/gradle-1.4-rc-2'
14:34:22.100 [Connection worker] DEBUG o.g.t.i.c.l.DefaultToolingImplementationLoader - Using tooling provider classpath: [/home/denis/dev/gradle/gradle-1.4-rc-2/lib/reflectasm-1.07-shaded.jar, /home/denis/dev/gradle/gradle-1.4-rc-2/lib/logback-core-1.0.9.jar, /home/denis/dev/gradle/gradle-1.4-rc-2/lib/dom4j-1.6.1.jar, /home/denis/dev/gradle/gradle-1.4-rc-2/lib/slf4j-api-1.7.2.jar, /home/denis/dev/gradle/gradle-1.4-rc-2/lib/gradle-base-services-1.4-rc-2.jar, /home/denis/dev/gradle/gradle-1.4-rc-2/lib/gradle-open-api-1.4-rc-2.jar, /home/denis/dev/gradle/gradle-1.4-rc-2/lib/jansi-1.2.1.jar, /home/denis/dev/gradle/gradle-1.4-rc-2/lib/jcl-over-slf4j-1.7.2.jar, /home/denis/dev/gradle/gradle-1.4-rc-2/lib/gradle-cli-1.4-rc-2.jar, /home/denis/dev/gradle/gradle-1.4-rc-2/lib/native-platform-linux-amd64-0.2.jar, /home/denis/dev/gradle/gradle-1.4-rc-2/lib/native-platform-windows-i386-0.2.jar, /home/denis/dev/gradle/gradle-1.4-rc-2/lib/native-platform-0.2.jar, /home/denis/dev/gradle/gradle-1.4-rc-2/lib/gradle-ui-1.4-rc-2.jar, /home/denis/dev/gradle/gradle-1.4-rc-2/lib/gradle-tooling-api-1.4-rc-2.jar, /home/denis/dev/gradle/gradle-1.4-rc-2/lib/jul-to-slf4j-1.7.2.jar, /home/denis/dev/gradle/gradle-1.4-rc-2/lib/commons-lang-2.6.jar, /home/denis/dev/gradle/gradle-1.4-rc-2/lib/objenesis-1.2.jar, /home/denis/dev/gradle/gradle-1.4-rc-2/lib/jarjar-1.3.jar, /home/denis/dev/gradle/gradle-1.4-rc-2/lib/gradle-native-1.4-rc-2.jar, /home/denis/dev/gradle/gradle-1.4-rc-2/lib/asm-4.0.jar, /home/denis/dev/gradle/gradle-1.4-rc-2/lib/jsch-0.1.46.jar, /home/denis/dev/gradle/gradle-1.4-rc-2/lib/gradle-wrapper-1.4-rc-2.jar, /home/denis/dev/gradle/gradle-1.4-rc-2/lib/groovy-all-1.8.6.jar, /home/denis/dev/gradle/gradle-1.4-rc-2/lib/logback-classic-1.0.9.jar, /home/denis/dev/gradle/gradle-1.4-rc-2/lib/minlog-1.2.jar, /home/denis/dev/gradle/gradle-1.4-rc-2/lib/gradle-launcher-1.4-rc-2.jar, /home/denis/dev/gradle/gradle-1.4-rc-2/lib/jna-3.2.7.jar, /home/denis/dev/gradle/gradle-1.4-rc-2/lib/javax.inject-1.jar, /home/denis/dev/gradle/gradle-1.4-rc-2/lib/kryo-2.20.jar, /home/denis/dev/gradle/gradle-1.4-rc-2/lib/gradle-core-1.4-rc-2.jar, /home/denis/dev/gradle/gradle-1.4-rc-2/lib/asm-all-4.0.jar, /home/denis/dev/gradle/gradle-1.4-rc-2/lib/ivy-2.2.0.jar, /home/denis/dev/gradle/gradle-1.4-rc-2/lib/gradle-base-services-groovy-1.4-rc-2.jar, /home/denis/dev/gradle/gradle-1.4-rc-2/lib/native-platform-osx-universal-0.2.jar, /home/denis/dev/gradle/gradle-1.4-rc-2/lib/commons-collections-3.2.1.jar, /home/denis/dev/gradle/gradle-1.4-rc-2/lib/jna-posix-1.0.3.jar, /home/denis/dev/gradle/gradle-1.4-rc-2/lib/jaxen-1.1.jar, /home/denis/dev/gradle/gradle-1.4-rc-2/lib/log4j-over-slf4j-1.7.2.jar, /home/denis/dev/gradle/gradle-1.4-rc-2/lib/ant-1.8.4.jar, /home/denis/dev/gradle/gradle-1.4-rc-2/lib/commons-io-1.4.jar, /home/denis/dev/gradle/gradle-1.4-rc-2/lib/guava-11.0.2.jar, /home/denis/dev/gradle/gradle-1.4-rc-2/lib/ant-launcher-1.8.4.jar, /home/denis/dev/gradle/gradle-1.4-rc-2/lib/native-platform-windows-amd64-0.2.jar, /home/denis/dev/gradle/gradle-1.4-rc-2/lib/gradle-messaging-1.4-rc-2.jar, /home/denis/dev/gradle/gradle-1.4-rc-2/lib/native-platform-linux-i386-0.2.jar, /home/denis/dev/gradle/gradle-1.4-rc-2/lib/jcip-annotations-1.0.jar]
14:34:22.191 [Connection worker] DEBUG o.g.t.i.provider.DefaultConnection - Provider implementation created.
14:34:22.280 [Connection worker] DEBUG o.g.t.i.provider.DefaultConnection - Embedded executer support created.
14:34:22.289 [Connection worker] DEBUG o.g.t.i.provider.DefaultConnection - Configuring logging to level: INFO
Tooling API uses target gradle version: 1.4-rc-2.
Starting Gradle daemon
Starting daemon process: workingDir = /home/denis/.gradle/daemon/1.4-rc-2, daemonArgs: [/home/denis/dev/jdk/jdk1.7.0_03/bin/java, -XX:MaxPermSize=256m, -XX:+HeapDumpOnOutOfMemoryError, -Xmx1024m, -Dfile.encoding=UTF-8, -cp, /home/denis/dev/gradle/gradle-1.4-rc-2/lib/gradle-launcher-1.4-rc-2.jar, org.gradle.launcher.daemon.bootstrap.GradleDaemon, 1.4-rc-2, /home/denis/.gradle/daemon, 10000, 0dbe37e2-b164-4b34-b8c8-608f25971d79, -XX:MaxPermSize=256m, -XX:+HeapDumpOnOutOfMemoryError, -Xmx1024m, -Dfile.encoding=UTF-8]
Starting process 'Gradle build daemon'. Working directory: /home/denis/.gradle/daemon/1.4-rc-2 Command: /home/denis/dev/jdk/jdk1.7.0_03/bin/java -XX:MaxPermSize=256m -XX:+HeapDumpOnOutOfMemoryError -Xmx1024m -Dfile.encoding=UTF-8 -cp /home/denis/dev/gradle/gradle-1.4-rc-2/lib/gradle-launcher-1.4-rc-2.jar org.gradle.launcher.daemon.bootstrap.GradleDaemon 1.4-rc-2 /home/denis/.gradle/daemon 10000 0dbe37e2-b164-4b34-b8c8-608f25971d79 -XX:MaxPermSize=256m -XX:+HeapDumpOnOutOfMemoryError -Xmx1024m -Dfile.encoding=UTF-8
An attempt to initialize for well behaving parent process finished.
Successfully started process 'Gradle build daemon'
Process 'Gradle build daemon' finished with exit value 0 (state: DETACHED)
An attempt to start the daemon took 0.449 secs.
Connected to the daemon. Dispatching Build{id=23b6fb9f-88fc-4c88-acc5-5135b97d027f.1, currentDir=/home/denis/project/java/gradle-test} request.
Download http://repo1.maven.org/maven2/commons-collections/commons-collections/3.1/commons-collections-3.1.pom
Download http://repo1.maven.org/maven2/org/jboss/netty/netty/3.2.0.Final/netty-3.2.0.Final.pom
Download http://repo1.maven.org/maven2/org/jboss/jboss-parent/5/jboss-parent-5.pom
Download http://repo1.maven.org/maven2/commons-collections/commons-collections/3.1/commons-collections-3.1-sources.jar
Download http://repo1.maven.org/maven2/org/jboss/netty/netty/3.2.0.Final/netty-3.2.0.Final-sources.jar
Download http://repo1.maven.org/maven2/commons-collections/commons-collections/3.1/commons-collections-3.1.jar
Download http://repo1.maven.org/maven2/org/jboss/netty/netty/3.2.0.Final/netty-3.2.0.Final.jar
Download http://repo1.maven.org/maven2/junit/junit/4.10/junit-4.10.pom

BUILD SUCCESSFUL

Total time: 6.912 secs
Wed Jan 30 14:34:29 MSK 2013: Project resolve is complete
-----------------> Listing modules <----------------
    -----------------> Module quickstart <----------------
Dependency: IdeaLibraryDependency{file=/home/denis/Downloads/gradle-repo/caches/artifacts-23/filestore/commons-collections/commons-collections/3.1/jar/40fb048097caeacdb11dbb33b5755854d89efdeb/commons-collections-3.1.jar, source=/home/denis/Downloads/gradle-repo/caches/artifacts-23/filestore/commons-collections/commons-collections/3.1/source/a48ca211fd2a564425c2cb9b90cb0f9158cfce52/commons-collections-3.1-sources.jar, javadoc=null, exported=true, scope='IdeaDependencyScope{scope='COMPILE'}', id='GradleModuleVersion{group='commons-collections', name='commons-collections', version='3.1'}'}, scope: IdeaDependencyScope{scope='COMPILE'}
Dependency: IdeaLibraryDependency{file=/home/denis/Downloads/gradle-repo/caches/artifacts-23/filestore/org.jboss.netty/netty/3.2.0.Final/bundle/3bf21bdf3d23cd92358e756ec96fe546d9019a51/netty-3.2.0.Final.jar, source=/home/denis/Downloads/gradle-repo/caches/artifacts-23/filestore/org.jboss.netty/netty/3.2.0.Final/source/70ada9bc814c47df839d5221137139cd0dd9e951/netty-3.2.0.Final-sources.jar, javadoc=null, exported=true, scope='IdeaDependencyScope{scope='COMPILE'}', id='GradleModuleVersion{group='org.jboss.netty', name='netty', version='3.2.0.Final'}'}, scope: IdeaDependencyScope{scope='COMPILE'}
Dependency: IdeaLibraryDependency{file=/home/denis/Downloads/gradle-repo/caches/artifacts-23/filestore/junit/junit/4.10/jar/e4f1766ce7404a08f45d859fb9c226fc9e41a861/junit-4.10.jar, source=/home/denis/Downloads/gradle-repo/caches/artifacts-23/filestore/junit/junit/4.10/source/6c98d6766e72d5575f96c9479d1c1d3b865c6e25/junit-4.10-sources.jar, javadoc=null, exported=false, scope='IdeaDependencyScope{scope='TEST'}', id='GradleModuleVersion{group='junit', name='junit', version='4.10'}'}, scope: IdeaDependencyScope{scope='TEST'}
Dependency: IdeaLibraryDependency{file=/home/denis/Downloads/gradle-repo/caches/artifacts-23/filestore/org.hamcrest/hamcrest-core/1.1/jar/860340562250678d1a344907ac75754e259cdb14/hamcrest-core-1.1.jar, source=/home/denis/Downloads/gradle-repo/caches/artifacts-23/filestore/org.hamcrest/hamcrest-core/1.1/source/2ccf1154d1a8936042a8a742dc3e611d02ac7213/hamcrest-core-1.1-sources.jar, javadoc=null, exported=false, scope='IdeaDependencyScope{scope='TEST'}', id='GradleModuleVersion{group='org.hamcrest', name='hamcrest-core', version='1.1'}'}, scope: IdeaDependencyScope{scope='TEST'}
-----------------> Finishing <----------------

The most important information here is that

  1. GRADLE_USER_HOME is defined;
  2. Gradle tooling api uses it for storing downloaded artifacts;

The problem is that ~/.gradle dir is also created during that. It has the following content:

denis@unit-311:~/.gradle$ find .
.
./daemon
./daemon/1.4-rc-2
./daemon/1.4-rc-2/daemon-22433.out.log
./daemon/1.4-rc-2/registry.bin
./daemon/1.4-rc-2/registry.bin.lock

It looks like a tooling api bug as it should modify only contents of the directory specified at $GRADLE_USER_HOME



 Comments   
Comment by Denis Zhdanov [ 30/Jan/13 ]

Corresponding IntelliJ IDEA ticket - IDEA-100033

Comment by Benjamin Muschko [ 15/Nov/16 ]

As announced on the Gradle blog we are planning to completely migrate issues from JIRA to GitHub.

We intend to prioritize issues that are actionable and impactful while working more closely with the community. Many of our JIRA issues are inactionable or irrelevant. We would like to request your help to ensure we can appropriately prioritize JIRA issues you’ve contributed to.

Please confirm that you still advocate for your JIRA issue before December 10th, 2016 by:

  • Checking that your issues contain requisite context, impact, behaviors, and examples as described in our published guidelines.
  • Leave a comment on the JIRA issue or open a new GitHub issue confirming that the above is complete.

We look forward to collaborating with you more closely on GitHub. Thank you for your contribution to Gradle!

Comment by Benjamin Muschko [ 10/Feb/17 ]

Thanks again for reporting this issue. We haven't heard back from you after our inquiry from November 15th. We are closing this issue now. Please create an issue on GitHub if you still feel passionate about getting it resolved.

Generated at Wed Jun 30 12:28:04 CDT 2021 using Jira 8.4.2#804003-sha1:d21414fc212e3af190e92c2d2ac41299b89402cf.