Gradle modifies the location of the local repository

As the saying goes, the fit is the best.
There is no comparison between gradle and maven here. Just tell me, how a paranoid maven user tried to use gradle experience.

I have been using maven for many years, and I have a nexus on my machine.
Recently I saw that a demo needs gradle to run, so I plan to try it.

First of all, the download and configuration of gradle is not a problem for a programmer. If it can't be done, you may not be suitable for this line of work.
Under Win7, set the environment variable directly with setx.
First set the gradle installation directory or the decompressed directory. At least bin and lib should be kept in this directory, and other files or directories can be deleted as much as you like.

[html]  view plain copy  
 
  1. setx GRADLE_HOME "E:\gradle"  

 

 

Then add the gradle executable path to the Path variable. Why add it? Because you want to execute a command (exe, bat, cmd, etc.) without a path, you need to add the path where the command is located in the command search path list.

[html]  view plain copy  
 
  1. setx Path ".;%%GRADLE_HOME%%\bin;"  

 

 

Like Maven, gradle needs to cache the jar package locally.
Gradle can reuse maven's private repository and central repository. No matter what the central warehouse is, most paranoiacs care about how gradle reuses the jar packages already downloaded by maven first, and those jar packages that are not downloaded to the gradle cache directory.

On the gradle official website and some tutorials given by Du Niang, they all say

[html]  view plain copy  
 
  1. repositories {  
  2.    mavenLocal()  
  3. }  

 

 

命令行切到demo目录,执行gradle jettyRun试了试,C盘用户目录刷刷的下东西。
原因是gradle默认是下载C盘用户目录的。
度娘是不会告诉你如何设置一个长期的缓存目录的。谷哥知道,但是需要懂科学。
谷哥给了多种设置方法:系统环境变量、jvm环境变量、gradle命令行参数等等。我选择比较简单也相对长期的系统环境变量设置方式。
把gradle缓存目录指向了gradle安装目录下的.gradle目录

[html]  view plain  copy
 
  1. setx GRADLE_USER_HOME %GRADLE_HOME%\.gradle  

 

 

设置完成后,删了C盘用户目录gradle下的东西。重新启动gradle jettyRun。这回没往C盘用户目录写了,写在了%GRADLE_HOME%\.gradle 这个目录里。mavenLocal()拼写没错啊,build.gradle也没错啊,但是以往maven下过的jar包还是在重复下,果断ctrl+c。

度娘问了半天是没结果的,从谷哥给的建议找到官网,上面介绍了复用maven本地仓库的搜索路径,主要是通过maven的settings.xml。
maven配置用的默认的那些朋友,自然不会碰到我这样的问题。因为可以直接在C盘用户目录找到这个settings.xml。
如果设置了M2_HOME的那些朋友,自然也不会碰到我这样的问题。因为可以直接在M2_HOME下的conf目录找到这个settings.xml。

像我这样只配了maven可执行路径到Path环境变量的朋友,自然会碰到我这样的问题。解决方法很easy,把M2_HOME这个环境变量加上,值就是maven的安装目录。

[html]  view plain  copy
 
  1. setx M2_HOME %MAVEN_HOME%  

 

 

After the setup is complete, delete the contents of the %GRADLE_HOME%\.gradle directory. Restart gradle jettyRun. I was happy to see that the demo was successfully started, and the jar package was not repeated, but the existing packages in the maven local warehouse were used.

For maveners who love toss and want to try gradle.

Off topic, it seems that the maven plugin of eclipse has been integrated in recent versions. At least kepler and luna have. The gradle plugin should be installed from the springsource plugin library. The painful CMCC network speed went down several times to half of the time. Fortunately, I borrowed some scientific postures according to the cat and the tiger, and the agent was installed smoothly. The configuration in the gradle plugin is recommended to be manually written as the address of the gradle installation directory. With the default configuration, gradle will be downloaded by itself and the cache will be downloaded to the C drive.

Many times I need to find the dependency tree of the jar package. The maven plugin is very intuitive to see, and the gradle plugin is a headache. I definitely don't use it. After thinking about it, although gradle is relatively simple and powerful (in terms of executing custom tasks), I finally feel that maven is more suitable for me. For me, maven is the best tool.

 

http://blog.csdn.net/kl28978113/article/details/53018225

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326906784&siteId=291194637