Primer
Gradle is a good use of compiler tools. A little bit less convenient place that, Maven and some development environment only provides. So sometimes, we need to use Gradle build a Maven need POM.xml file. The following methods can turn into gradle maven project, provided gradle project directory structure remains the same with the maven conventions, namely / src / main / java this set.
Generated pom.xml
method one:
1, open build.gradle file, add the following in the build.gradle (group, version can modify, the artifactId default directory name)
apply plugin: 'java' apply plugin: 'maven' group = 'com.angei' version = '1.0.0' sourceCompatibility = 1.8
plugins format may be as follows:
plugins { id 'java' id 'maven' } group = 'com.angei' version = '1.0.0' sourceCompatibility = 1.8
2, performed at the terminal
gradle install
After successful, poms file in the build directory generated in the folder pom-default.xml, will be renamed pom.xml copied to the root directory of the project can be.
Pom-default.xml generated as follows:
1 <?xml version="1.0" encoding="UTF-8"?> 2 <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" 3 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 4 <modelVersion>4.0.0</modelVersion> 5 <groupId>com.angei</groupId> 6 <artifactId>gradle-first</artifactId> 7 <version>1.0.0</version> 8 <dependencies> 9 <dependency> 10 <groupId>junit</groupId> 11 <artifactId>junit</artifactId> 12 <version>4.12</version> 13 <scope>test</scope> 14 </dependency> 15 </dependencies> 16 </project>
Second way:
1, content is added in the colored portion build.gradle file:
1 buildscript { 2 repositories { 3 mavenCentral() 4 } 5 dependencies { 6 classpath("org.springframework.boot:spring-boot-gradle-plugin:1.3.3.RELEASE") 7 } 8 } 9 10 apply plugin: 'java' 11 apply plugin: 'jacoco' 12 apply plugin: 'spring-boot' 13 apply plugin: 'maven' 14 15 sourceCompatibility = 1.8 16 compileJava.options.encoding = 'UTF-8' 17 18 19 group = 'com.101tec' 20 // Options for naming the JAR file 21 archivesBaseName = 'trackr-backend' 22 version = '1.0' 23 if(project.hasProperty('teamcity')) { 24 version += '-build-' + project.teamcity['build.number'] 25 } else { 26 version += '-localbuild' 27 } 28 29 30 sourceCompatibility = 1.8 31 32 repositories { 33 mavenCentral() 34 } 35 36 springBoot { 37 executable = true 38 } 39 40 dependencies { 41 compile "org.springframework.boot:spring-boot-starter-data-rest" 42 compile "org.springframework.boot:spring-boot-starter-data-jpa" 43 compile "org.springframework.boot:spring-boot-starter-mail" 44 compile "org.springframework.boot:spring-boot-starter-integration" 45 compile "org.springframework.boot:spring-boot-starter-security" 46 47 // not included in boot 48 compile "org.springframework.integration:spring-integration-mail:4.2.5.RELEASE" 49 compile "org.springframework.security.oauth:spring-security-oauth2:2.0.11.RELEASE" 50 51 compile "com.h2database:h2" 52 compile "postgresql:postgresql:9.1-901.jdbc4" 53 compile "org.flywaydb:flyway-core" 54 55 compile("org.xhtmlrenderer:flying-saucer-pdf-itext5:9.0.6") 56 compile("org.thymeleaf:thymeleaf:2.1.3.RELEASE") 57 58 compile "org.projectlombok:lombok:1.12.4" 59 60 compile "org.glassfish:javax.json:1.0" 61 62 63 testCompile "org.springframework.boot:spring-boot-starter-test" 64 testCompile("org.echocat.jomon:testing:1.4.3") { 65 exclude group: "org.mockito" 66 } 67 testCompile "org.mockito:mockito-core:1.9.5" 68 testCompile "com.jayway.jsonpath:json-path" 69 testCompile "org.apache.httpcomponents:httpclient" 70 } 71 72 73 task wrapper(type: Wrapper) { 74 gradleVersion = '2.2' 75 } 76 77 task createPom << { 78 pom { 79 project { 80 groupId 'com.angei' 81 artifactId 'gradle-first' 82 version '1.0.0' 83 } 84 }.writeTo("$buildDir/pom.xml") 85 }
This createPom which the task to whatever name you like, such as createPom, mavenPom, testPom, etc., and then only needs to be performed.
2, the terminal performs:
gradle createPom
The successful implementation of Figure
Pom.xml generated as follows:
<?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>com.angei</groupId>
<artifactId>gradle-first</artifactId>
<version>1.0.0</version>
<dependencies>
<dependency>
<groupId>com.feidee.laoyeye</groupId>
<artifactId>feidee-laoyeye-service-dto</artifactId>
<version>1.0.0-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.feidee.finance</groupId>
<artifactId>finance-lib-javaweb</artifactId>
<version>1.0.0-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-cache</artifactId>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-aop</artifactId>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-freemarker</artifactId>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.kafka</groupId>
<artifactId>kafka-clients</artifactId>
<version>1.1.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.springframework.kafka</groupId>
<artifactId>spring-kafka</artifactId>
<version>1.3.7.RELEASE</version>
<scope>compile</scope>
<exclusions>
<exclusion>
<artifactId>kafka-clients</artifactId>
<groupId>org.apache.kafka</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-all</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.13.1</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>