Maven篇
1.安装与配置(windows环境)
- 下载zip包
maven zip download.png
- 下载后,解压到自己的本地目录下
解压.png
- 解压文件后的文件目录添加到系统环境变量path中
例如:我的目录路径为:C:\maven\apache-maven-3.6.0\bin
,追加到path环境变量最后,记得与之前的内容用;隔开
以上操作完成后,maven就已经安装完成,win+R
,输入cmd
,打开控制台,mvn -version
测试安装完成
- 配置(配置本地仓库路径,配置使用国内镜像)
打开settings.xml
(该文件位于下载的zip文件解压后的文件conf目录中),例如我的文件路径为:C:\maven\apache-maven-3.6.0\conf
,增加两部分内容,一部分为本地仓库地址设置:
<localRepository>C:\Users\Administrator\.m2\repository</localRepository>
一部分为配置使用国内镜像(使用的阿里镜像):
<mirror>
<id>alimaven</id>
<name>aliyun maven</name>
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
<!--mirrorOf>central</mirrorOf-->
<mirrorOf>*</mirrorOf>
</mirror>
至此,maven的所有的安装配置完成,可以在开发中使用了,还有一点需要注意的,eclipe中,由于maven的配置默认使用的是用户的默认设置,需要在使用的时候指定一下自己具体的配置文件。
settings配置在eclipe中的设置.png
Gradle篇
1.安装(Mac环境)
brew install gradle
gradle -v
2.创建项目
mkdir GradleExample
cd GradleExample
gradle init
cmd界面会给出需要创建的项目类型
Select type of project to generate:
1: basic
2: cpp-application
3: cpp-library
4: groovy-application
5: groovy-library
6: java-application
7: java-library
8: kotlin-application
9: kotlin-library
10: scala-library
Enter selection (default: basic) [1..10]
创建一个java程序,选择6
Select build script DSL:
1: groovy
2: kotlin
Enter selection (default: groovy) [1..2]
选择脚本语言,默认选择groovy
Select test framework:
1: junit
2: testng
3: spock
Enter selection (default: junit) [1..3]
选择测试框架,默认选择junit
Project name (default: GradleExample):
工程名,默认是当前目录的目录名
Source package (default: GradleExample):
源码包名,默认也是当前目录的目录名
完成后,项目创建成功
BUILD SUCCESSFUL in 4m 10s
2 actionable tasks: 2 executed
项目目录结构:
image.png
当我们需要将项目打包成jar包发布时,需要在build.gradle编译配置文件中,加入项目编译的相关配置
/*
* This file was generated by the Gradle 'init' task.
*
* This generated file contains a sample Java project to get you started.
* For more details take a look at the Java Quickstart chapter in the Gradle
* User Manual available at https://docs.gradle.org/5.4.1/userguide/tutorial_java_projects.html
*/
plugins {
// Apply the java plugin to add support for Java
id 'java'
// Apply the application plugin to add support for building an application
id 'application'
}
repositories {
// Use jcenter for resolving your dependencies.
// You can declare any Maven/Ivy/file repository here.
jcenter()
}
dependencies {
// This dependency is found on compile classpath of this component and consumers.
implementation 'com.google.guava:guava:27.0.1-jre'
// Use JUnit test framework
testImplementation 'junit:junit:4.12'
}
// Define the main class for the application
mainClassName = 'GradleExample.App'
apply plugin: 'java'
jar {
baseName = 'first-gradle-demo'
version = '0.1.0'
manifest {
attributes 'Main-Class': 'GradleExample.App'
}
}
执行命令
./gradlew build
编译完成,目录结构
生成的jar包在libs目录下
当然,gradle还有其他很多丰富的功能,后续会整理进来
网友评论