Maven & Gradle 如何从中央仓库下载Jar包

https://mvnrepository.com/    maven 中央仓库

 

gradle可以轻松的完成Android项目对第三方jar包文件的依赖下载,再也不需要我们手动下载jar包,然后拷贝到lib目录,再手动添加依赖到项目中了,通过gradle可以快速的从中央仓库中下载jar文件,然后自动依赖到项目中

 

1. 搜索jar包

https://mvnrepository.com/ 

 

2.

例如输入:volley

 

3. 点击 标注 的版本号

 

 

4.

Maven 配置:

 

Gradle配置:

 

 使用bat脚本下载jar包 方法:

1. 桌面新建文件夹“maven中央仓库jar包下载”

新建文件:download-jar-from-maven.bat

::使用DOS命令执行mvn命令:将pom.xml文件所依赖的jar包从maven中央仓库拷贝到本地

call mvn -f pom.xml dependency:copy-dependencies

@pause

 

 

2. 新建:pom.xml ,内容如下(下载 volley jar包为例):

<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <modelVersion>4.0.0</modelVersion>

  <groupId>test.download</groupId>
  <artifactId>test.download</artifactId>
  <version>1.0.0</version>

  <dependencies>
    <dependency>
        <groupId>com.mcxiaoke.volley</groupId>
        <artifactId>library</artifactId>
        <version>1.0.19</version>
    </dependency>
  </dependencies>
</project>

 

说明:上面 黄色标注 的内容就是从如下截图中拷贝过来的

 

 

也可以用如下写法:

<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <modelVersion>4.0.0</modelVersion>

  <groupId>test.download</groupId>
  <artifactId>test.download</artifactId>
  <version>1.0.0</version>

  <dependencies>
    <dependency>
      <groupId>com.mcxiaoke.volley</groupId>
      <artifactId>library</artifactId>
      <version>${volley-library-version}</version>
    </dependency>
  
  </dependencies>

  <properties>
      <volley-library-version>1.0.19</volley-library-version>
  </properties>
</project>

 

 

 

3.双击“download-jar-from-maven.bat”运行就行了,其他不用管

脚本运行过程说明:

a. 首先创建本地maven仓库,默认的本机maven仓库 是在:C:\Users\xxx\.m2\repository ,第一次需要几分钟时间,耐心等待

 

b. 下载jar包。

最后截图:

 

脚本所在目录新生成“target”文件夹,所下载的jar文件在 target\dependency 目录下面,同时jar包在“C:\Users\xxx\.m2\repository\...”下面也有一份(通过所下载的jar文件名结合Everything工具可以找到文件) 

 

 

 

 

最后附:

swagger editor工具导出的pom.xml,其中所需jar包下载:

 

<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <modelVersion>4.0.0</modelVersion>

  <groupId>test.download</groupId>
  <artifactId>test.download</artifactId>
  <version>1.0.0</version>

  <dependencies>
    <dependency>
        <groupId>com.mcxiaoke.volley</groupId>
        <artifactId>library</artifactId>
        <version>1.0.19</version>
    </dependency>
    
    <dependency>
      <groupId>org.apache.httpcomponents</groupId>
      <artifactId>httpcore</artifactId>
      <version>${httpcomponents-httpcore-version}</version>
    </dependency>
    <dependency>
      <groupId>org.apache.httpcomponents</groupId>
      <artifactId>httpclient-android</artifactId>
      <version>${httpcomponents-httpclient-version}</version>
    </dependency>
    <dependency>
      <groupId>org.apache.httpcomponents</groupId>
      <artifactId>httpmime</artifactId>
      <version>${httpcomponents-httpmime-version}</version>
    </dependency>

    <dependency>
      <groupId>com.google.code.gson</groupId>
      <artifactId>gson</artifactId>
      <version>${google-code-gson-version}</version>
    </dependency>
    
    <dependency>
      <groupId>io.swagger</groupId>
      <artifactId>swagger-annotations</artifactId>
      <version>${swagger-annotations-version}</version>
    </dependency>
  </dependencies>
  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <httpcomponents-httpcore-version>4.4.4</httpcomponents-httpcore-version>
    <httpcomponents-httpmime-version>4.5.2</httpcomponents-httpmime-version>
    <httpcomponents-httpclient-version>4.3.3</httpcomponents-httpclient-version>
    <google-code-gson-version>2.6.2</google-code-gson-version>
    <swagger-annotations-version>1.5.8</swagger-annotations-version>
  </properties>
</project>

 

 

 

 

延伸:

https://jingyan.baidu.com/article/4b07be3c93ce6048b380f3dd.html  gradle如何从中央仓库下载Jar包

https://blog.csdn.net/win7system/article/details/51260282   Maven中央仓库地址整理

https://blog.csdn.net/Mr_Tony/article/details/72955949   通过gradle下载最新依赖包的一种方式

https://blog.csdn.net/ha000/article/details/51142254   Gradle下载的依赖包位置

转载于:https://www.cnblogs.com/onelikeone/p/10069225.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值