Gradle提供了几种部署构建工件(artifacts)存储库的方法
将工件的签名部署到Maven存储库时,还需要签署已发布的POM文件
使用Maven插件发布
Gradle默认提供maven-publish插件。 它用于发布gradle脚本。 看看下面的代码。
apply plugin: ‘java‘ apply plugin: ‘maven-publish‘ publishing { publications { mavenJava(MavenPublication) { from components.java } } repositories { maven { url "$buildDir/repo" } } }SQL
当应用Java和maven-publish插件时,有几个发布选项。 看看下面的代码,它会将项目部署到远程仓库
apply plugin: ‘groovy‘apply plugin: ‘maven-publish‘group ‘workshop‘version = ‘1.0.0‘publishing {publications {mavenJava(MavenPublication) {from components.java}}repositories {maven {default credentials for a nexus repository managercredentials {username ‘admin‘password ‘mypasswd‘}// 发布maven存储库的urlurl "http://localhost:8080/nexus/content/repositories/releases/"}}}
将项目从Maven转换为Gradle
有一个特殊的命令用于将Apache Maven pom.xml文件转换为Gradle构建文件,如果此任务已经知道使用的所有Maven插件。
在本节中,以下pom.xml 的maven配置将转换为Gradle项目。创建一个D:/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.0http://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><groupId>com.example.app</groupId><artifactId>example-app</artifactId><packaging>jar</packaging><version>1.0.0-SNAPSHOT</version><dependencies><dependency><groupId>junit</groupId><artifactId>junit</artifactId><version>4.11</version><scope>test</scope></dependency></dependencies></project>
可以命令行上使用以下命令,然后生成以下Gradle配置内容。
D:/> gradle init --type pomStarting a Gradle Daemon, 1 incompatible and 1 stopped Daemons could not be reused,use --status for details:wrapper:initMaven to Gradle conversion is an incubating feature.BUILD SUCCESSFULTotal time: 11.542 secs
init任务依赖于包装器任务,因此它创建了一个Gradle包装器。
生成的build.gradle文件类似于以下内容。
apply plugin: ‘java‘apply plugin: ‘maven‘group = ‘com.yiibai.app‘version = ‘1.0.0-SNAPSHOT‘description = """"""sourceCompatibility = 1.5targetCompatibility = 1.5repositories {maven { url "http://repo.maven.apache.org/maven2" }}dependencies {testCompile group: ‘junit‘, name: ‘junit‘, version:‘4.11‘}