0104 gradle entry

background

gradle official website is www.gradle.org, title presentation is: accelerate developer productivity, translated: improving developer productivity;
brief: from the phone app to the micro-services, from small start-up companies to large enterprises, gradle help the team build, automation, better and faster delivery of software.

Three features

  1. Build Anything (to build everything)

    You can choose to use Java, C ++, Python language, a single warehouse or multiple warehouses, gradle package can be deployed on any platform, which is dependent on the extremely flexible gradle to build;

  2. Automate Everything (everything Automation)

Use gradle rich API and sophisticated plug-ecology, modeling, integrated, systematic variety of software. Integration of these plug-ins can be done with a purpose automation.

  1. Deliver Faster (Fast Delivery)

Elegance, speed building, ignored from the compiler to advanced caching, or even more, gradle pursuit of sustained performance, ensure that your team can continue to be delivered;

installation steps

macos I use, here I used to download the latest package to install native gradle to my environment;

Proceed as follows:

  1. Into your working directory: cd ~
  2. Download instructions: wget https://downloads.gradle-dn.com/distributions/gradle-6.0.1-all.zip
  3. Decompression: unzip gradle-6.0.1-all.zip
  4. Rename: mv gradle-6.0.1 gradle
  5. Into the implementation directory: cd gradle/bin
  6. Perform directory replication Address: pwdcopy path is assumed to / usr / tool / gradle / bin
  7. ohMyZSH I use, so I increased the path under my ~ / .zshrc EXPORT PATH=$PATH:/usr/tool/gradle/bin
  8. Validation: gradlesee gradle version number to identify a successful installation;
  9. Delete the downloaded package to save space:rm -rf /usr/tool/gradle-6.0.1-all.zip

Begin the tutorial

java developer, java main concern is to build respect, first emptying yourself, throw away maven, starting from 0;

java application

The basic java development;

step:

  1. mkdir demo_gradle_application;
  2. cd demo_gradle_application ;
  3. gradle init
  4. Introduce directory
    file

Name settings.gradle.kts here to configure the project;
build.gradle.kts here to configure the warehouse, plug-ins and dependence;

file

  1. Construct

gradlew build

  1. test

Test coverage report

file

  1. run

./gradlew run 最后看到打印出hello world表示成功!

成果:

  • 如何使用gradle生成一个java application;
  • 生成的代码结构;
  • 如何执行gradle构建以及查看测试报告;
  • 如何执行java应用使用run任务通过gradle插件;

代码

java library

java库,可以被其它项目引用或者说复用;
file

步骤:

  1. gradle init , 选择 library ;
  2. 结构如上图;

同application类型;
settings.gradle.kts 主要设置项目的名字
build.gradle.kts主要配置插件,依赖仓库,依赖;
源码,测试目录同maven的约定;

  1. ./gradlew build 构建jar包;
  2. 定制jar包

定制版本号: 在build.gradle.kts中 增加版本号;

version = "1.0-SNAPSHOT"

然后执行打包,可以得到带版本的jar包;

定制jar包的 library name 和 library version;
在build.gradle.kts中

tasks{
    jar{
        manifest{
            mapOf("Implementation-Title" to project.name , 
            "Implementation-Version" to project.version
            )
        }
    }
}
  1. 生成jar包, ./gradlew jar
  2. 生成API文档 , ./gradlew javadoc

成果:

  • 生成了java库;
  • 生成文件的目录结构;
  • 执行构建并查看测试报告;
  • 定制生成jar包的版本和name
  • 生成API文档;

java web

使用gradle创建web项目;
gradle有一个war插件用来构建javaWEB应用,并提供了一个gretty查来用来测试和部署web应用到jetty或者tomcat中;例子展示了如何构建一个简单的webapp并部署到jetty使用gretty插件,你也可以学到如何写servlet的单元测试通过使用Mockit框架,并学到如何使用gretty和selenium写功能测试;

目录说明

  • src/main/java java源码目录
  • src/main/webapp 页面目录
  • src/test/java 测试代码目录

步骤:

  1. 引入依赖;
  2. servlet的代码
  3. Introduction page code
  4. Introducing gretty plug;
  5. Simulation tests servlet, using Mockito;
  6. Analog functional testing, using webdriverManager, selenium;
  7. Test run;

Results:

  • Use war plug-in to define web application;
  • Adding servlet and JSP;
  • Use gretty plug-deploy applications;
  • Use mockit unit testing;
  • Use gretty selenum and functional testing;

Code: https://github.com/carterbrother/springbootpractice/tree/master/demo_gradle_webapp

java springboot

idea of ​​using gradle

The original is not easy, please indicate the source.

Guess you like

Origin www.cnblogs.com/snidget/p/12149837.html