gradle maven

In this post, we are going to discuss gradle vs maven. We will also see how to run gradle commands from Command Prompt”.

在这篇文章中,我们将讨论gradle vs maven。 我们还将看到如何从“命令提示符”中运行gradle命令。

We have already compared maven vs gradle in What is Gradle and Gradle Tutorial posts. Here we will look more into gradle commands and corresponding maven commands.

在“ 什么是Gradle和Gradle教程”帖子中,我们已经比较了maven vs gradle。 在这里,我们将进一步研究gradle命令和相应的maven命令。

We are going to use Gradle Spring MVC example program to demonstrate most of the gradle commands in this post.

我们将使用Gradle Spring MVC示例程序来演示本文中的大多数gradle命令。

Gradle vs Maven (Gradle vs Maven)

Both gradle and maven are build and dependency management tools. We will look into following points in comparing gradle vs maven.

gradle和maven都是构建和依赖项管理工具。 在比较gradle与maven时,我们将研究以下几点。

  1. Gradle vs Maven Commands
    Gradle vs Maven命令
  2. Install Gradle Project To Maven Repo
    将Gradle项目安装到Maven回购
  3. Maven vs Gradle Build Script Major Elements
    Maven vs Gradle构建脚本主要元素
  4. Maven vs Gradle Commands In Brief
    Maven vs Gradle命令简介

Gradle vs Maven命令 (Gradle vs Maven Commands)

As we all are already very much familiar with maven build tool, it’s better to compare maven commands with gradle commands to learn gradle easily.

由于我们都已经非常熟悉Maven构建工具,因此最好将Maven命令与gradle命令进行比较,以轻松学习gradle。

In this section, we will try to take each maven command and find out the counterpart in gradle.

在本节中,我们将尝试采用每个maven命令并在gradle中找出对应的命令。

Like Maven, We can run gradle commands by using some IDEs like Eclipse IDE, Spring STS IDE, IntelliJ IDEA etc. and also from command prompt.

像Maven一样,我们可以通过使用某些IDE(例如Eclipse IDE,Spring STS IDE,IntelliJ IDEA等)以及从命令提示符下运行gradle命令。

To know version: First and foremost thing we should know is our software version so that we can understand which features we can use in our application development.

要知道版本 :首先,我们应该知道的是我们的软件版本,以便我们能够了解可以在应用程序开发中使用的功能。

To know version of maven, we need to use the following maven command:

要了解Maven的版本,我们需要使用以下maven命令:

mvn --version

To know version of gradle, we need to use the following gradle command:

要了解gradle的版本,我们需要使用以下gradle命令:

gradle --version

To create JAR/WAR/EAR
To deploy our application into any Web or Application servers, we need to create our application JAR/WAR/EAR files.

创建JAR / WAR / EAR
要将应用程序部署到任何Web或应用程序服务器中,我们需要创建应用程序JAR / WAR / EAR文件。

To create JAR/WAR/EAR, we need to use the following maven command:

要创建JAR / WAR / EAR,我们需要使用以下maven命令:

mvn package

To create JAR/WAR/EAR in gradle, we need to use the following gradle command:

要在gradle中创建JAR / WAR / EAR,我们需要使用以下gradle命令:

gradle assemble

Before executing this command, open command prompt at our project root directory and execute “dir” command to see the content of the current working directory.

在执行此命令之前,请在我们项目的根目录中打开命令提示符,然后执行“ dir”命令以查看当前工作目录的内容。

Here we can observe that other than “src” folder, we have nothing. Execute gradle assemble command now.

在这里我们可以看到,除了“ src”文件夹外,我们什么都没有。 立即执行gradle assemble命令。

Here we can see “BUILD SUCCESSFUL”. This command, first compiles all source files and then creates war file. Now again execute “dir” command to see the content of the current working directory.

在这里我们可以看到“ BUILD SUCCESSFUL”。 此命令首先编译所有源文件,然后创建war文件。 现在再次执行“ dir”命令以查看当前工作目录的内容。

We can observe newly generate war file at ${PROJECT_ROOT_DIR}/build/libs/ as shown below.

我们可以在$ {PROJECT_ROOT_DIR} / build / libs /中观察到新生成的war文件,如下所示。

We can observe compiled *.class files at ${PROJECT_ROOT_DIR}/build/classes/main/[our-package-structure]/*.class.

我们可以在${PROJECT_ROOT_DIR}/build/classes/main/[our-package-structure]/*.class 。class中观察已编译的* .class文件。

To run Unit Tests
To run only JUnit tests without creating our application JAR/WAR/EAR file, we need to use the following commands:

运行单元测试
要仅运行JUnit测试而不创建我们的应用程序JAR / WAR / EAR文件,我们需要使用以下命令:

To compile and run unit tests:

要编译和运行单元测试:

mvn test
gradle test

To Skip Unit Tests
To skip JUnit tests and do required other tasks, we need to use the following commands:

跳过单元测试
要跳过JUnit测试并执行所需的其他任务,我们需要使用以下命令:

mvn install -DskipTests
#OR
mvn install -Dmaven.test.skip=true
gradle -x test install

To run JUnits and create JAR/WAR/EAR
To run JUnit tests first then create our application JAR/WAR/EAR files, we need to use the following commands:

运行JUnits并创建JAR / WAR / EAR
要首先运行JUnit测试,然后创建我们的应用程序JAR / WAR / EAR文件,我们需要使用以下命令:

To compile, tests and assemble:

编译,测试和组装:

mvn test package
gradle build

NOTE: In both maven and gradle, we can pipe two or more commands and execute them at once as shown above.

注意:在maven和gradle中,我们都可以通过管道传递两个或多个命令并立即执行它们,如上所示。

To clean
It’s always recommended to clean everything before compile and build our application code.

清洁
始终建议在编译和构建应用程序代码之前先清理所有内容。

To delete build directory:

要删除构建目录:

mvn clean
gradle clean

To Install
To compile, build and install to local maven repository, we need to use following commands.

安装
要编译,构建并安装到本地Maven存储库,我们需要使用以下命令。

mvn install
gradle install

To deploy Web Application
To deploy application WAR/EAR file into server, we need to use following commands.

部署Web应用程序
要将应用程序WAR / EAR文件部署到服务器中,我们需要使用以下命令。

mvn deploy

To run on Jetty embedded server:

要在Jetty嵌入式服务器上运行:

mvn jetty:run

Gradle has separate commands for each server to run created WAR/WAR file.

Gradle对于每个服务器都有单独的命令来运行创建的WAR / WAR文件。

To run our Web Application with already created WAR file in an embedded Jetty server:

要在嵌入式Jetty服务器中使用已创建的WAR文件运行我们的Web应用程序 ,请执行以下操作:

gradle jettyRun

To build WAR file, deploy and run it in an embedded jetty server:

要构建WAR文件,请在嵌入式码头服务器中部署并运行它:

mvn jetty:run-war
gradle jettyRunWar

To create JAR file
To create JAR file from compiled class files, we need to use following command.

创建JAR文件
要从编译的类文件创建JAR文件,我们需要使用以下命令。

mvn jar
gradle jar
#or
gradle libs

Eclipse IDE Commands
To Generate a Project and all Eclipse required files.

Eclipse IDE命令
生成项目和所有Eclipse所需的文件。

mvn eclipse:eclipse
gradle eclipse

To clean all Eclipse required files:

要清除所有Eclipse必需的文件:

mvn eclipse:clean
gradle cleanEclipse

将Gradle项目安装到Maven回购 (Install Gradle Project To Maven Repo)

We can use gradle install command to build and install our application JAR/WAR file to our local maven repository.

我们可以使用gradle install命令来构建应用程序JAR / WAR文件并将其安装到本地Maven存储库。

We cannot execute “gradle install” command with our previous gradle project example from Gradle Spring MVC” because we have not specified any maven plugins in build.gradle file.

我们无法在Gradle Spring MVC的上一个gradle项目示例中执行“ gradle install”命令,因为我们没有在build.gradle文件中指定任何maven插件。

Now we will change our build.gradle file to include this functionality. Please follow these simple steps.

现在,我们将更改build.gradle文件以包含此功能。 请按照以下简单步骤操作。

  1. Add maven plugin to build.gradle file
    将Maven插件添加到build.gradle文件
  2. apply plugin: 'maven'
  3. Add GroupId and our JAR/WAR file version
    添加GroupId和我们的JAR / WAR文件版本
  4. Add build.gradle file root elements as shown below.

    如下所示添加build.gradle文件根元素。

    group = "com.journaldev"
    version = "1.0"

    If we don’t specify version element here, then it uses war file version declaration as shown below.

    如果我们在此处未指定version元素,则它将使用war文件的版本声明,如下所示。

    war {baseName = 'SpringMVCExample'version = '1.0.0-BUILD-SNAPSHOT'
    }

    That’s it. Now our gradle install will copy application jar/war file to maven repository too.

    而已。 现在,我们的gradle安装也将应用程序jar / war文件也复制到maven存储库。

  5. Our complete and new build.gradle file
    我们完整的新build.gradle文件
  6. apply plugin: "java"
    apply plugin: "eclipse"
    apply plugin: "war"
    apply plugin: 'maven'sourceCompatibility = 1.7group = "com.journaldev"
    version = "1.0"war {baseName = 'SpringMVCExample'version = '1.0.0-BUILD-SNAPSHOT'
    }repositories {mavenCentral()
    }dependencies {compile("org.springframework:spring-context:4.0.0.RELEASE")compile("org.springframework:spring-webmvc:4.0.0.RELEASE")compile("org.aspectj:aspectjrt:1.7.4")compile("javax.inject:javax.inject:1")compile("javax.servlet:servlet-api:2.5")compile("javax.servlet:jstl:1.2")compile("javax.servlet.jsp:jsp-api:2.1")   compile("org.slf4j:slf4j-api:1.7.5")compile("org.slf4j:jcl-over-slf4j:1.7.5")compile("org.slf4j:slf4j-log4j12:1.7.5")compile("log4j:log4j:1.2.15")testCompile("junit:junit:4.7")
    }
  7. Execute “gradle install” command
    执行“渐变安装”命令
  8. Observe our Local Maven Repository
    观察我们的本地Maven存储库

Maven vs Gradle构建脚本主要元素 (Maven vs Gradle Build Script Major Elements)

If we observe both maven’s pom.xml and gradle’s build.gradle file, we can find the following things.

如果我们同时观察到maven的pom.xml和gradle的build.gradle文件,则可以发现以下内容。

Maven Elements Gradle Elements
<groupId> Gradle’s “group” Element
<artifactId> Gradle’s “baseName” Element
<version> Gradle’s “version” Element
Maven元素 Gradle元素
<groupId> Gradle的“群组”元素
<artifactId> Gradle的“ baseName”元素
<版本> Gradle的“版本”元素
  • Like Maven, we can integrate existing ANT tasks in Gradle and use them in our projects.
    像Maven一样,我们可以将现有的ANT任务集成到Gradle中,并在我们的项目中使用它们。
  • Like Maven, we can create our own project specific Gradle tasks and use them in our projects.
    像Maven一样,我们可以创建自己的项目特定的Gradle任务,并在我们的项目中使用它们。
  • We can even Integrate Maven tasks with Gradle build tool.
    我们甚至可以将Maven任务与Gradle构建工具集成在一起。

Maven vs Gradle命令 (Maven vs Gradle commands)

The following table lists all important maven and gradle commands.

下表列出了所有重要的maven和gradle命令。

Maven Command Gradle Command
mvn package gradle assemble
mvn test gradle test
mvn clean gradle clean
mvn –help gradle –help
mvn install gradle install
mvn –version gradle –version
Maven命令 Gradle命令
mvn包 Gradle组装
MVN测试 摇动测试
MVN清洁 Gradle清洁
mvn –帮助 gradle –帮助
mvn安装 gradle安装
mvn –version gradle –version

It’s a brief comparison between Maven vs Gradle build tools. It’s not enough to include everything in one post to list all commands with suitable examples. I hope we have given enough basics to dig into these two tools further to become an expert.

这是Maven与Gradle构建工具之间的简要比较。 仅在一篇文章中包含所有内容以列出所有带有适当示例的命令是不够的。 我希望我们已经提供了足够的基础知识,可以进一步研究这两个工具,从而成为专家。

Reference: Official user guide

参考: 官方用户指南

翻译自: https://www.journaldev.com/8396/gradle-vs-maven

gradle maven

gradle maven_Gradle vs Maven相关推荐

  1. gradle maven_Gradle – Maven的观点

    gradle maven 正如我博客的读者所知道的, 我有点像Maven迷 . 我从2007年8月左右开始使用Maven,从没有回过头. 但是,与其他所有情况一样,"变化是唯一的常数&quo ...

  2. 下一代构建工具 Gradle ,比 Maven 强在哪里!

    作者 :乐百川 本文:toutiao.com/i6824937779193971207 相信使用Java的同学都用过Maven,这是一个非常经典好用的项目构建工具.但是如果你经常使用Maven,可能会 ...

  3. cordova使用Gradle构建下载maven太慢,使用阿里云镜像

    修改build.gradle: buildscript {repositories {maven{ url 'http://maven.aliyun.com/nexus/content/groups/ ...

  4. 在 build.gradle.kts 添加 maven 仓库

    在 build.gradle.kts 添加 maven 仓库 使用 kotlin script DSL 配置 build.gradle.kts 时,添加 maven 仓库的方式如下: reposito ...

  5. build.gradle.kts添加maven仓库

    build.gradle中添加maven仓库写法 mavenCentral()maven { url 'https://jitpack.io' }maven { url 'https://maven. ...

  6. Gradle 设置 本地maven仓库及发布mavenLocal()路径的方法

    2019独角兽企业重金招聘Python工程师标准>>> 最近在学习Gradle,在配置maven仓库时遇到一个很奇怪的问题.因为之前已经在自己机器上下载了一些maven的本地缓存,所 ...

  7. Error:Cause: org/gradle/api/publication/maven/internal/DefaultMavenFactory Android

    首先,要看一下自己的项目使用 "Gradle版本" 接着要看一下项目根目录的build.gradle文件中的"dependencies"的 classpath ...

  8. Gradle使用本地maven仓库

    一.基本配置 在repositories下添加mavenLocal()方法 plugins {id 'java' }group 'com.luzelong' version '1.0-SNAPSHOT ...

  9. Gradle配置文件转Maven

    gradle的配置文件是build.gradle maven的配置文件是pom.xml 需要在gradle项目中生成对应maven的pom文件的话,如下操作: 在 build.gradle 中添加如下 ...

最新文章

  1. 某程序员吐槽:前端开发被哄抢,专科学历能进大厂;客户端开发找工作难如登天,985本硕拿不到一个offer!...
  2. 中国版 Ubuntu Kylin 14.04 LTS 麒麟操作系统中文版发布下载 (Ubuntu天朝定制版)
  3. python怎么理解函数的参数_理解Python中函数的参数
  4. 【Android 逆向】ELF 文件格式总结 ★★★
  5. 和Java相关的书籍,想成为架构师的请收藏一下啊
  6. python如何封装成可调用的库_在python中如何以异步的方式调用第三方库提供的同步API...
  7. 郑州it java_郑州Java网站开发
  8. javq接口_java 接口详解
  9. jvm中的新生代Eden和survivor区
  10. python实现bt下载器_10行 Python代码使用磁力链接批量下载种子
  11. android内录音软件,安卓内录声音软件(能内录音频的手机软件)
  12. JVM学习--垃圾回收机制
  13. linux动态监控系统
  14. python出行轨迹记录软件_看看过去跑过哪些地方,用Python和高德API绘制跑步轨迹...
  15. Java学习:流程控制
  16. sql多表查询及多表连接查询
  17. Excel 数字转日期类型
  18. 小飞升值记——(23)
  19. 黑苹果EFI引导启动文件,华硕X99 Deluxe+E5-1660v3+蓝宝石 RX 580 8G+macos10.14.x(7)
  20. 服务端技术方案模板参考

热门文章

  1. python web开发实录
  2. [独孤九剑]持续集成实践(二)– MSBuild语法入门
  3. Oracle 隔离级别
  4. STL源码剖析学习十四:算法之set相关算法
  5. C++ 内存分配 学习笔记
  6. 程序设计基础(C语言)教学案例-序言
  7. 8位二进制数的原码、反码、补码以及它能表示的范围
  8. 多态加opp内置函数
  9. 从今天开始 好好规划自己
  10. 页面固定定位超出一屏