当前位置: 首页 > news >正文

【项目构建】Gradle入门

本文适用:

  1. 不知道什么是项目构建,可以了解下AntMavenGradle的区别。
  2. 知道什么是项目构建,了解AntMaven,可以看到Gradle是怎么做的。
  3. 知道什么是项目构建,了解AntMavenGradle,可以帮本文审校下,多谢。

文章目录

    • Gradle是什么
    • Gradle项目结构
    • 依赖关系
      • 新旧版本
      • 作用
    • 指定Java版本

Gradle是什么

Ant
Ant是用Java编写的,可以用于包含JavaCC++等多种语言的构建工具,其中的典型优势是支持跨平台。

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
在这里插入图片描述

  1. Gradle directory to store wrapper files and more
  2. Gradle version catalog for dependency management
  3. Gradle wrapper scripts
  4. Gradle settings file to define a root project name and subprojects
  5. Gradle build scripts of the two subprojects - subproject-a and subproject-b
  6. Source code and/or additional files for the projects

settings.gradle:判断有哪些项目需要初始化,加载所有需要初始化的项目的。可以类比maven中的module管理。
build.gradle: 为每个项目创建project对象,可类比maven中的pom.xml。

依赖关系

新旧版本

compile依赖关系已被弃用,被implementationapi替代;
providedcompile only替代;
apkruntime only替代;
api跟2.x版本的compile完全相同。

作用

  • compileOnly:只在编译时有效,不会参与打包 可以在自己的moudle中使用该方式依赖一些比如com.android.support,gson这些使用者常用的库,避免冲突。
  • 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' // 目标字节码兼容版本
http://www.lryc.cn/news/509813.html

相关文章:

  • Electron -- Electron应用主要核心(二)
  • 【前端开发】HTML+CSS+JavaScript前端三剑客的基础知识体系了解
  • git命令恢复/还原某个文件、删除远程仓库中的文件
  • 二十一、Ingress 进阶实践
  • ES学习Promise对象(九)
  • 寻找适合小户型的开源知识库open source knowledge base之路
  • Linux高级--2.6 网络面试问题
  • 在 CentOS 7 上安装 Node.js 20 并升级 GCC、make 和 glibc
  • 音视频入门基础:MPEG2-TS专题(20)——ES流简介
  • 五子棋小游戏设计(Matlab)
  • 基于Pycharm与数据库的新闻管理系统(3)MongoDB
  • WebRtc webrtc-streamer部署
  • CVPR-2024 | 具身导航模型大一统!NaviLLM:学习迈向具身导航的通用模型
  • CAN201 Introduction to Networking(计算机网络)Pt.2 传输层
  • git仓库多人协作新建分支 合并到主分支流程详解
  • Visual Studio 使用 GitHub Copilot 与 IntelliCode 辅助编码 【AI辅助开发系列】
  • 【时间之外】IT人求职和创业应知【74】-运维机器人
  • 高阶:基于Python paddleocr库 提取pdf 文档高亮显示的内容
  • STM32项目之环境空气质量检测系统软件设计
  • 重温设计模式--原型模式
  • 输变电资质分一级、二级,新办从二级开始,三级已取消
  • 浏览器http缓存问题
  • 结构化Prompt:让大模型更智能的秘诀
  • 威联通NAS部署openwrt软路由保姆级教程附镜像文件
  • 《计算机网络(第7版)-谢希仁》期末考试复习题和答案(总结整理)
  • windows和mac共享文件夹访问教程
  • 【PPTist】网格线、对齐线、标尺
  • Leetcode3218. 切蛋糕的最小总开销 I
  • ECCV-2024 | 指令不够用、大模型来生成!BEVInstructor:基于BEV感知和大模型的视觉语言导航指令生成
  • 【UE5.3.2 】引擎中安装RiderLink插件