1.创建主项目
打开命令行,创建目录,执行如下命令:
(base) ouyangMBP:gradle-test2 ouyang$ gradle init
Select type of project to generate:
1: basic
2: application
3: library
4: Gradle plugin
Enter selection (default: basic) [1..4] 1
Select build script DSL:
1: Groovy
2: Kotlin
Enter selection (default: Groovy) [1..2] 1
查看生成的目录树:
(base) ouyangMBP:gradle-test2 ouyang$ tree
.
├── build.gradle
├── gradle
│ └── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
└── settings.gradle
其中gradle-wrapper是帮你自动设置和安装gradle的工具,同时它还提供了gradlew和gradlew.bat这两个执行文件,用来执行gradle的任务。
2.创建App项目
在项目主目录下创建目录app,然后进入app目录,如下创建app项目
(base) ouyangMBP:gradle-test2 ouyang$ mkdir app
(base) ouyangMBP:gradle-test2 ouyang$ cd app/
(base) ouyangMBP:app ouyang$ gradle init
Select type of project to generate:
1: basic
2: application
3: library
4: Gradle plugin
Enter selection (default: basic) [1..4] 2
Select implementation language:
1: C++
2: Groovy
3: Java
4: Kotlin
5: Swift
Enter selection (default: Java) [1..5] 3
Select build script DSL:
1: Groovy
2: Kotlin
Enter selection (default: Groovy) [1..2] 1
Select test framework:
1: JUnit 4
2: TestNG
3: Spock
4: JUnit Jupiter
Enter selection (default: JUnit 4) [1..4] 1
Project name (default: app):
Source package (default: app): com.test
查看app项目,生成的目录树
(base) ouyangMBP:app ouyang$ tree
.
├── build.gradle
├── gradle
│ └── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── settings.gradle
└── src
├── main
│ ├── java
│ │ └── com
│ │ └── test
│ │ └── App.java
│ └── resources
└── test
├── java
│ └── com
│ └── test
│ └── AppTest.java
└── resources
3.修改主项目
打开settings.gradle
# 增加下面这一行
include 'app'