以 gson 为例,几种方式的第三方包的引入
普通 project
- 下载 jar 包, 保存到本地
menu
->file
->project structure
->project settings
->libraries
->➕
maven
- 在
pox.xml
里面加入
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.5</version>
</dependency>
完整的
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>group1</groupId>
<artifactId>maven_playground</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.5</version>
</dependency>
</dependencies>
</project>
gradle
- 创建项目后没有src 目录,新建src目录,在src下新建main, main 上右键-> mark as source dir
- 在 build.gradle 文件中加入
implementation 'com.google.code.gson:gson:2.8.5'
完整:
plugins {
id 'java'
}
group 'playground'
version '1.0-SNAPSHOT'
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
implementation 'com.google.code.gson:gson:2.8.5'
testCompile group: 'junit', name: 'junit', version: '4.12'
}
gradle-groovy
和普通的gradle 区别不打,注意groovy 和 gradle 互相调用时需要定义好包名(没有包名时不同groovy文件间的相互调用会报错 )
aught: groovy.lang.MissingMethodException: No signature of method: static…