gradle java项目初识总结

gradle当下其实相比于maven正变得越来越流行的一款构建工具,我们每一个开发人员都很有必要了解一下。今天我来剖析下gradle java项目结构。

build.gradle

这是gradle项目的构建脚本文件

settings.gradle

这是gradle环境配置文件

build目录

gradle默认的输出产物目录

用gradle来构建JAVA项目

在build.gradle中添加如下脚本:

plugins {
    id 'java'
}

或者

apply plugin : 'java'

这个时候你的工程
主代码应该放在src/main/java
测试代码放在src/test/java

自定义源代码结构

如果想把
主代码放在src
测试代码放在test
构建脚本加如下配置

sourceSets {
    main {
        java {
            srcDirs = ['src']
        }
    }
    test {
        java {
            srcDirs = ['test']
        }
    }
}

Gradle Tasks

应用了以上java plugin,在idea中我们可以看到有如下可用任务
这里写图片描述

Tasks下面列出了所有可能任务的分组,以及每个分组下面有具体的哪些任务
gradle tasks
如同执行以上命令输出如下:

------------------------------------------------------------
All tasks runnable from root project
------------------------------------------------------------

Build tasks
-----------
assemble - Assembles the outputs of this project.
build - Assembles and tests this project.
buildDependents - Assembles and tests this project and all projects that depend on it.
buildNeeded - Assembles and tests this project and all projects it depends on.
classes - Assembles main classes.
clean - Deletes the build directory.
jar - Assembles a jar archive containing the main classes.
testClasses - Assembles test classes.

Build Setup tasks
-----------------
init - Initializes a new Gradle build.
wrapper - Generates Gradle wrapper files.

Documentation tasks
-------------------
javadoc - Generates Javadoc API documentation for the main source code.

Help tasks
----------
buildEnvironment - Displays all buildscript dependencies declared in root project 'mybatisplus'.
components - Displays the components produced by root project 'mybatisplus'. [incubating]
dependencies - Displays all dependencies declared in root project 'mybatisplus'.
dependencyInsight - Displays the insight into a specific dependency in root project 'mybatisplus'.
dependentComponents - Displays the dependent components of components in root project 'mybatisplus'. [incubating]
help - Displays a help message.
model - Displays the configuration model of root project 'mybatisplus'. [incubating]
projects - Displays the sub-projects of root project 'mybatisplus'.
properties - Displays the properties of root project 'mybatisplus'.
tasks - Displays the tasks runnable from root project 'mybatisplus'.

Verification tasks
------------------
check - Runs all checks.
test - Runs the unit tests.

gradle build
执行以上命令,则会执行构建任务

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值