单页网站修改,网络工程师考试报名官网,做互联网平台要多少钱,网络营销促销形式本文适用#xff1a; 不知道什么是项目构建#xff0c;可以了解下Ant#xff0c;Maven#xff0c;Gradle的区别。知道什么是项目构建#xff0c;了解Ant#xff0c;Maven#xff0c;可以看到Gradle是怎么做的。知道什么是项目构建#xff0c;了解Ant#xff0c;Maven 不知道什么是项目构建可以了解下AntMavenGradle的区别。知道什么是项目构建了解AntMaven可以看到Gradle是怎么做的。知道什么是项目构建了解AntMavenGradle可以帮本文审校下多谢。 文章目录 Gradle是什么Gradle项目结构依赖关系新旧版本作用 指定Java版本 Gradle是什么
Ant Ant是用Java编写的可以用于包含Java、C、C等多种语言的构建工具其中的典型优势是支持跨平台。 Apache Ant is a Java library and command-line tool whose mission is to drive processes described in build files as targets and extension points dependent upon each other. The main known usage of Ant is the build of Java applications. Ant supplies a number of built-in tasks allowing to compile, assemble, test and run Java applications. Ant can also be used effectively to build non Java applications, for instance C or C applications. More generally, Ant can be used to pilot any type of process which can be described in terms of targets and tasks. Why another build tool Maven Maven使用项目对象模型POM来管理项目依赖根据约定胜于配置convention over configuration理念采取依赖坐标和冲突仲裁能多种方式来管理依赖和解决冲突广泛应用于多种项目。 Apache Maven is a software project management and comprehension tool. Based on the concept of a project object model (POM), Maven can manage a project’s build, reporting and documentation from a central piece of information. Gradle Gradle 构建工具是一款快速、可靠、适应性强的开源构建自动化工具拥有优雅、可扩展的声明式构建语言。最典型特征是可扩展。 Gradle is the open source build system of choice for Java, Android, and Kotlin developers. From mobile apps to microservices, from small startups to big enterprises, it helps teams deliver better software, faster. Why Gradle? Gradle项目结构
Gradle project structure
Gradle directory to store wrapper files and moreGradle version catalog for dependency managementGradle wrapper scriptsGradle settings file to define a root project name and subprojectsGradle build scripts of the two subprojects - subproject-a and subproject-bSource code and/or additional files for the projects
settings.gradle:判断有哪些项目需要初始化,加载所有需要初始化的项目的。可以类比maven中的module管理。 build.gradle: 为每个项目创建project对象可类比maven中的pom.xml。
依赖关系
新旧版本
compile依赖关系已被弃用被implementation和api替代; provided被compile only替代; apk被runtime only替代; api跟2.x版本的compile完全相同。
作用
compileOnly只在编译时有效不会参与打包 可以在自己的moudle中使用该方式依赖一些比如com.android.supportgson这些使用者常用的库避免冲突。runtimeOnly只在生成apk的时候参与打包编译时不会参与很少用。testImplementation只在单元测试代码的编译以及最终打包测试apk时有效。debugImplementation只在debug模式的编译和最终的debug apk打包时有效releaseImplementation仅仅针对Release 模式的编译和最终的Release apk打包。api会把依赖库传给使用者使用者的项目External Libraries 中能够看的见。可以在其他module使用会参与打包。implementation当其他模块依赖此模块时此模块使用implementation声明的依赖包只限于模块内部使用不允许其他模块使用。
指定Java版本 project的java运行版本不是本地java版本 以下是如何在build.gradle文件中配置: 应用Java插件
plugins { id java
}指定版本
sourceCompatibility 11 // 源代码兼容版本
targetCompatibility 11 // 目标字节码兼容版本