Bootstrap

Gradle Maven部署,转化

参考:(易百教程)http://www.yiibai.com/gradle/gradle_deployment.html

目录:

Gradle部署:

cmd>gradle build会将现有的项目打包到build->libs下。

Gradle Maven部署:

        Gradle默认提供maven-publish插件。 它用于发布gradle脚本。

  本地部署:

apply plugin: 'maven-publish'

publishing {
   publications {
      mavenJava(MavenPublication) {
         from components.java
      }
   }

repositories {
      maven {
        url "D:/Repository/maven/"
      }
   }
}

 

  私服部署:

apply plugin: 'maven-publish'

publishing {
   publications {
      mavenJava(MavenPublication) {
         from components.java
      }
   }

repositories {
      maven {
        
         credentials {
            username 'admin'
            password 'admin111'
         }
         // 发布maven存储库的url
         url "http://192.168.1.91:8084/nexus/content/repositories/MavenTest"
      }
   }
}

cmd> gradle publish

Maven转化为Gradle:

  gradle有个maven转化的命令

  cmd>  gradle init --type pom (注意:一定要是两个中划线)

  转化前的pom.xml

pom
  1 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  2   xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  3   <modelVersion>4.0.0</modelVersion>
  4   <groupId>com.web.mt</groupId>
  5   <artifactId>MavenWeb</artifactId>
  6   <packaging>war</packaging>
  7   <version>1.0.0</version>
  8   <name>MavenWeb Maven Webapp</name>
  9   <url>http://maven.apache.org</url>
 10   <properties>
 11     <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
 12       <junit-version>3.8.1</junit-version>
 13     <spring-version>5.0.0.RELEASE</spring-version>
 14     <jstl-version>1.2</jstl-version>
 15     <logback-version>1.2.3</logback-version>
 16   </properties>
 17   <repositories>
 18       <repository>
 19           <id>MavenTest</id>
 20           <name>MavenTest Snap</name>
 21           <snapshots>
 22               <enabled>true</enabled>
 23           </snapshots>
 24           <url>http://127.0.0.1:8081/nexus/content/repositories/MavenTest/</url>
 25       </repository>
 26   </repositories>
 27   <dependencies>
 28   
 29   <dependency>
 30    <groupId>com.denny.mt</groupId>
 31    <artifactId>MavenTest</artifactId>
 32    <version>1.0-SNAPSHOT</version>
 33   </dependency>
 34   
 35   
 36     <dependency>
 37       <groupId>junit</groupId>
 38       <artifactId>junit</artifactId>
 39       <version>${junit-version}</version>
 40       <scope>test</scope>
 41     </dependency>
 42     
 43 <dependency>
 44          <groupId>ojdbc</groupId>
 45          <artifactId>ojdbc</artifactId>
 46          <scope>system</scope>
 47          <version>6</version>
 48          <systemPath>${basedir}\src\lib\ojdbc-6.jar</systemPath>
 49 </dependency>
 50     
 51     
 52     <dependency>
 53         <groupId>org.springframework</groupId>
 54         <artifactId>spring-core</artifactId>
 55         <version>${spring-version}</version>
 56         <exclusions>
 57             <exclusion>
 58                 <artifactId>spring-jcl</artifactId>
 59                 <groupId>org.apache.commons.logging</groupId>
 60             </exclusion>
 61         </exclusions>
 62     </dependency>
 63     <dependency>
 64         <groupId>org.springframework</groupId>
 65         <artifactId>spring-webmvc</artifactId>
 66         <version>${spring-version}</version>
 67     </dependency>
 68     <dependency>
 69         <groupId>org.springframework</groupId>
 70         <artifactId>spring-web</artifactId>
 71         <version>${spring-version}</version>
 72     </dependency>
 73     <dependency>
 74         <groupId>ch.qos.logback</groupId>
 75         <artifactId>logback-classic</artifactId>
 76         <version>${logback-version}</version>
 77     </dependency>
 78     <dependency>
 79         <groupId>jstl</groupId>
 80         <artifactId>jstl</artifactId>
 81         <version>${jstl-version}</version>
 82     </dependency>
 83   </dependencies>
 84   <build>
 85     <finalName>MavenWeb</finalName>
 86     <plugins>
 87         <plugin>
 88             <groupId>org.apache.maven.plugins</groupId>
 89             <artifactId>maven-compiler-plugin</artifactId>
 90             <version>2.3.2</version>
 91             <configuration>
 92                 <source>1.8</source>
 93                 <target>1.8</target>
 94             </configuration>
 95         </plugin>
 96         <plugin>
 97             <groupId>org.apache.tomcat.maven</groupId>
 98             <artifactId>tomcat7-maven-plugin</artifactId>
 99             <version>2.2</version>
100             <configuration>
101                 <path>/MavenWeb</path>
102             </configuration>
103           </plugin>
104                       <!-- Eclipse project -->
105           <plugin>
106             <groupId>org.apache.maven.plugins</groupId>
107             <artifactId>maven-eclipse-plugin</artifactId>
108             <version>2.9</version>
109             <configuration>
110                     <!-- Always download and attach dependencies source code -->
111                 <downloadSources>true</downloadSources>
112                 <downloadJavadocs>false</downloadJavadocs>
113                 <!-- Avoid type mvn eclipse:eclipse -Dwtpversion=2.0 -->
114                 <wtpversion>2.0</wtpversion>
115             </configuration>
116           </plugin>
117           
118     </plugins>
119   </build>
120   <distributionManagement>
121   <repository>
122     <id>MavenTestPub</id>
123     <url>http://192.168.1.91:8081/nexus/content/repositories/MavenTestPub</url>
124   </repository>
125    <snapshotRepository>
126     <id>MavenTest</id>
127     <url>http://192.168.1.91:8081/nexus/content/repositories/MavenTest</url>
128   </snapshotRepository>
129 </distributionManagement>
130 </project>

 

  转化后的build.gradle

apply plugin: 'java'
apply plugin: 'maven'

group = 'com.web.mt'
version = '1.0.0'

description = """MavenWeb Maven Webapp"""

sourceCompatibility = 1.8
targetCompatibility = 1.8
tasks.withType(JavaCompile) {
	options.encoding = 'UTF-8'
}



repositories {
        
     maven { url "http://127.0.0.1:8081/nexus/content/repositories/MavenTest/" }
     maven { url "http://repo.maven.apache.org/maven2" }
}
dependencies {
    compile group: 'com.denny.mt', name: 'MavenTest', version:'1.0-SNAPSHOT'
    compile(group: 'org.springframework', name: 'spring-core', version:'5.0.0.RELEASE') {
exclude(module: 'spring-jcl')
    }
    compile group: 'org.springframework', name: 'spring-webmvc', version:'5.0.0.RELEASE'
    compile group: 'org.springframework', name: 'spring-web', version:'5.0.0.RELEASE'
    compile group: 'ch.qos.logback', name: 'logback-classic', version:'1.2.3'
    compile group: 'jstl', name: 'jstl', version:'1.2'
    testCompile group: 'junit', name: 'junit', version:'3.8.1'
    system group: 'ojdbc', name: 'ojdbc', version:'6'
}
build.gradle

 

运行:

  报错,本地配置的jar在转化后,不能被识别  

system group: 'ojdbc', name: 'ojdbc', version:'6'
------------------------------------------------
Could not find method system() for arguments

 

修改为:

    compile files('src/lib/ojdbc-6.jar')

本地其它平级项目嵌入:

settings.gradle文件:

  includeFlat 'MavenTest'

build.gradle文件:

  compile project(":MavenTest")

执行gradle build即可打成想要的jar包。

appPlugin 'java'   --build会打成jar包

appPlugin 'war'   --build会打成war包

appPlugin 'maven'   --build会打成pom包

 

转载于:https://www.cnblogs.com/DennyZhao/p/7737856.html

;