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下載的依賴包位置


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM