其他分享
首页 > 其他分享> > how to convert a Gradle build file to a Maven POM file

how to convert a Gradle build file to a Maven POM file

作者:互联网

目录

1. Gradle Build File

示例引用 Spring 实战(第 4 版)第 1 章 Spring 之旅

build.gradle

apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'

jar {
    baseName = 'knight'
    version =  '0.0.1-SNAPSHOT'
}

repositories {
    mavenLocal()
    mavenCentral()
}

dependencies {
    compile("org.springframework:spring-context:${springVersion}")
    compile("org.aspectj:aspectjweaver:${aspectJVersion}")
    compile("log4j:log4j:${log4jVersion}")

    testCompile("junit:junit:${junitVersion}")
    testCompile("org.mockito:mockito-core:${mockitoVersion}")
    testCompile("org.springframework:spring-test:${springVersion}")
}

task wrapper(type: Wrapper) {
    gradleVersion = '1.11'
}

2. Maven Plugin

build.gradle

apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'maven'

jar {
    baseName = 'knight'
    version =  '0.0.1-SNAPSHOT'
}

repositories {
    mavenLocal()
    mavenCentral()
}

group = 'org.example'
version = '0.0.1-SNAPSHOT'

dependencies {
    compile("org.springframework:spring-context:${springVersion}")
    compile("org.aspectj:aspectjweaver:${aspectJVersion}")
    compile("log4j:log4j:${log4jVersion}")

    testCompile("junit:junit:${junitVersion}")
    testCompile("org.mockito:mockito-core:${mockitoVersion}")
    testCompile("org.springframework:spring-test:${springVersion}")
}

3. convert

/Users/wuyong/spring/spring-in-action-4-samples/Chapter_01/knight

gradle install

/Users/wuyong/spring/spring-in-action-4-samples/Chapter_01/knight/build/poms

pom-default.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <modelVersion>4.0.0</modelVersion>
  <groupId>org.example</groupId>
  <artifactId>knight</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <dependencies>
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-context</artifactId>
      <version>4.0.7.RELEASE</version>
      <scope>compile</scope>
    </dependency>
    <dependency>
      <groupId>org.aspectj</groupId>
      <artifactId>aspectjweaver</artifactId>
      <version>1.7.2</version>
      <scope>compile</scope>
    </dependency>
    <dependency>
      <groupId>log4j</groupId>
      <artifactId>log4j</artifactId>
      <version>1.2.14</version>
      <scope>compile</scope>
    </dependency>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.11</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.mockito</groupId>
      <artifactId>mockito-core</artifactId>
      <version>1.9.5</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-test</artifactId>
      <version>4.0.7.RELEASE</version>
      <scope>test</scope>
    </dependency>
  </dependencies>
</project>

4. Import Maven Project to Eclipse

/Users/wuyong/spring/spring-in-action-4-samples/Chapter_01/knight

ls -a
.			.gradle			gradle.properties
..			build			gradlew
.DS_Store		build.gradle		gradlew.bat
.gitignore		gradle			src

拷贝 pom-default.xml 到当前目录,修改文件名为 pom.xml,文件内容修改如下:

pom.xml

<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>

  <groupId>org.example</groupId>
  <artifactId>knight</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>jar</packaging>

  <name>knight</name>
  <url>http://maven.apache.org</url>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <maven.compiler.target>1.8</maven.compiler.target>
    <maven.compiler.source>1.8</maven.compiler.source>
  </properties>

  <dependencies>
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-context</artifactId>
      <version>4.0.7.RELEASE</version>
      <scope>compile</scope>
    </dependency>
    <dependency>
      <groupId>org.aspectj</groupId>
      <artifactId>aspectjweaver</artifactId>
      <version>1.7.2</version>
      <scope>compile</scope>
    </dependency>
    <dependency>
      <groupId>log4j</groupId>
      <artifactId>log4j</artifactId>
      <version>1.2.14</version>
      <scope>compile</scope>
    </dependency>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.11</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.mockito</groupId>
      <artifactId>mockito-core</artifactId>
      <version>1.9.5</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-test</artifactId>
      <version>4.0.7.RELEASE</version>
      <scope>test</scope>
    </dependency>
  </dependencies>
</project>

保留 src 目录和 pom.xml 文件,其他文件全部删除。

Eclipse 导入 /Users/wuyong/spring/spring-in-action-4-samples/Chapter_01/knight

标签:convert,spring,mockito,Gradle,compile,file,knight,test,org
来源: https://www.cnblogs.com/clipboard/p/13762512.html