Java build tools Maven and Gradle

What is a build tool? A build tool is a program that aut...

What is a build tool?

A build tool is a program that automates the process of generating executable applications from source code. Build includes compiling, linking, and packaging code into usable or feasible forms.

Two popular building tools

Maven:

a. You know where the code is, where it's going
b. Have life cycle: can automatically execute the build process such as compile, test, package, etc
c. Have dependency management, warehouse management
d. Using pom.xml for management

Maven's configuration file is a. pom file. pom is the abbreviation of project object model. It is a file in Maven project, which is represented by XML. It includes basic information of the project, construction process, environmental information, dependency information, etc. Here is a simple example:

<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <artifactId>iBase4J-SYS-Web</artifactId> <name>iBase4J-SYS-Web</name> <packaging>jar</packaging> <url>http://maven.apache.org</url> <parent> <groupId>org.ibase4j</groupId> <artifactId>iBase4J</artifactId> <version>1.3.0</version> </parent> <properties> <server.port>8088</server.port> <moduleName>SysWeb</moduleName> <jar.dic>$/../</jar.dic> </properties> <dependencies> <dependency> <groupId>org.ibase4j</groupId> <artifactId>iBase4J-Biz-Facade</artifactId> <exclusions> <exclusion> <groupId>*</groupId> <artifactId>*</artifactId> </exclusion> </exclusions> </dependency> <dependency> <groupId>org.ibase4j</groupId> <artifactId>iBase4J-SYS-Facade</artifactId> <exclusions> <exclusion> <groupId>*</groupId> <artifactId>*</artifactId> </exclusion> </exclusions> </dependency> <!-- Spring --> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-webmvc</artifactId> </dependency> <!-- shiro --> <dependency> <groupId>org.apache.shiro</groupId> <artifactId>shiro-spring</artifactId> <version>$</version> </dependency> <!-- JSTL Label class --> <dependency> <groupId>jstl</groupId> <artifactId>jstl</artifactId> <version>1.2</version> </dependency> <dependency> <groupId>org.dom4j</groupId> <artifactId>dom4j</artifactId> <version>2.1.0</version> </dependency> <!-- excel --> <!-- <dependency> <groupId>net.sourceforge.jexcelapi</groupId> <artifactId>jxl</artifactId> <version>$</version> <exclusions> <exclusion> <groupId>log4j</groupId> <artifactId>log4j</artifactId> </exclusion> </exclusions> </dependency> <dependency> <groupId>org.apache.poi</groupId> <artifactId>poi</artifactId> <version>$</version> </dependency> <dependency> <groupId>org.apache.poi</groupId> <artifactId>poi-ooxml</artifactId> <version>$</version> </dependency> <dependency> <groupId>org.apache.poi</groupId> <artifactId>poi-ooxml-schemas</artifactId> <version>$</version> </dependency> --> <!-- File image processing --> <dependency> <groupId>net.coobird</groupId> <artifactId>thumbnailator</artifactId> <version>$</version> </dependency> <dependency> <groupId>com.jcraft</groupId> <artifactId>jsch</artifactId> <version>$</version> </dependency> <!-- swagger --> <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger2</artifactId> <version>$</version> </dependency> <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger-ui</artifactId> <version>$</version> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> </project>

Gradle :

In MAven's pom.xml, when we need to introduce a dependency, we need to tag its groupid, artificid and version. But in the build.gradle in gradle, you will find that you only need to connect the value s of the three and "call the compile function"

buildscript { repositories { mavenCentral() } dependencies { classpath("org.springframework.boot:spring-boot-gradle-plugin:1.2.6.RELEASE") } } dependencies { compile("org.springframework.boot:spring-boot-starter-web") { exclude module: "spring-boot-starter-tomcat" } compile("org.springframework.boot:spring-boot-starter-security") compile("org.springframework.boot:spring-boot-starter-data-jpa") testCompile("mysql:mysql-connector-java:5.1.25") }

In my work (java web), maven is used. In fact, I haven't used gradle well. Android seems to use the latter more often. Later, I will find a time to have a deep understanding of gradle

5 May 2020, 20:20 | Views: 7415

Add new comment

For adding a comment, please log in
or create account

0 comments