四时宝库

程序员的知识宝库

maven项目和gradle项目互相转化(maven gradle对比)

1.maven项目转gradle项目

  • cmd命令行进入maven项目的根目录(即pom.xml文件所在的路径),执行如下命令:

gradle init --type pom

执行完之后会生成build.gradle和setting.gradle等gradle项目的配置文件。

2.gradle项目转maven项目

  • 在你要转化的项目的build.gradle中加入以下代码:

apply plugin: 'java'apply plugin: 'maven'group = 'com.cachu'version = '1.0.0'sourceCompatibility = 1.7

group和version可以自己随便命名,artifactId默认为目录名称,sourceCompatibility是编译的jdk的版本。

  • cmd命令行进入你要转化的项目的路径下(即步骤1中build.gradle所在的目录),执行gradle install 命令。完整命令如下:

C:\Users\CatchU>d:D:\>cd D:\gitLocalRepo\innerManage\fmInnerManageD:\gitLocalRepo\innerManage\fmInnerManage>gradle installStarting a Gradle Daemon, 2 incompatible and 1 stopped Daemons could not be reused, use --status for details:compileJavaDownload https://jcenter.bintray.com/com/aliyun/aliyun-java-sdk-core/3.4.0/aliyun-java-sdk-core-3.4.0.pomDownload https://jcenter.bintray.com/org/json/json/20170516/json-20170516.pomDownload https://jcenter.bintray.com/javax/mail/mail/1.4/mail-1.4.jarDownload https://jcenter.bintray.com/com/aliyun/aliyun-java-sdk-core/3.4.0/aliyun-java-sdk-core-3.4.0.jarDownload https://jcenter.bintray.com/javax/activation/activation/1.1/activation-1.1.jarDownload https://jcenter.bintray.com/org/json/json/20170516/json-20170516.jar注: 某些输入文件使用了未经检查或不安全的操作。注: 有关详细信息, 请使用 -Xlint:unchecked 重新编译。:processResources:classes:war:installBUILD SUCCESSFULTotal time: 1 mins 9.01 secsD:\gitLocalRepo\innerManage\fmInnerManage>
  • 上面命令执行完毕之后会在build——poms——pom-default.xml找到pom文件,将其复制到项目下改为pom.xml即可。到此gradle项目转maven项目就完成了。 如果maven编译时出现如下警告:

WARNING] File encoding has not been set, using platform encoding GBK, i.e. build is platform dependent!

在pom.xml中加入如下代码:

<properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> </properties>

发表评论:

控制面板
您好,欢迎到访网站!
  查看权限
网站分类
最新留言
    友情链接