(Quick Reference)

3.7.10 部署到Maven存储库 - Reference Documentation

Authors: Graeme Rocher, Peter Ledbrook, Marc Palmer, Jeff Brown, Luke Daley, Burt Beckwith

Version: null

3.7.10 部署到Maven存储库

If you use Maven to build your Grails project, you can use the standard Maven targets mvn install and mvn deploy. If not, you can deploy a Grails project or plugin to a Maven repository using the maven-publisher plugin.

The plugin provides the ability to publish Grails projects and plugins to local and remote Maven repositories. There are two key additional targets added by the plugin:

  • maven-install - Installs a Grails project or plugin into your local Maven cache
  • maven-deploy - Deploys a Grails project or plugin to a remote Maven repository

By default this plugin will automatically generate a valid pom.xml for you unless a pom.xml is already present in the root of the project, in which case this pom.xml file will be used.

如果你是使用Maven来构建你的Grails工程,那么你可以使用标准的Maven目标命令(target)mvn installmvn deploy来安装部署。 如果不是,你可以通过maven-publisher插件来将Grails工程或者插件部署到Maven存储库。

此插件能够将Grails工程和插件发布到本地和远程的Maven存储库,下面是此插件额外的目标命令:

  • maven-install - 安装Grails工程或者插件到你本地的Maven缓存中
  • maven-deploy - 部署Grails工程或者插件到远程的Maven存储库中

如果你工程的根目录下边没有pom.xml,此插件将为你自动生成此文件,否则系统将直接使用已经存在的pom.xml文件。

maven-install

The maven-install command will install the Grails project or plugin artifact into your local Maven cache:

grails maven-install

In the case of plugins, the plugin zip file will be installed, whilst for application the application WAR file will be installed.

maven-install

maven-install命令将安装Grails工程或者插件到你本地的Maven缓存:

grails maven-install

当工程是插件时,将安装成zip文件;当是应用时,将安装成WAR文件。

maven-deploy

The maven-deploy command will deploy a Grails project or plugin into a remote Maven repository:

grails maven-deploy

It is assumed that you have specified the necessary <distributionManagement> configuration within a pom.xml or that you specify the id of the remote repository to deploy to:

grails maven-deploy --repository=myRepo

The repository argument specifies the 'id' for the repository. Configure the details of the repository specified by this 'id' within your grails-app/conf/BuildConfig.groovy file or in your $USER_HOME/.grails/settings.groovy file:

grails.project.dependency.distribution = {
    localRepository = "/path/to/my/local"
    remoteRepository(id: "myRepo", url: "http://myserver/path/to/repo")
}

The syntax for configuring remote repositories matches the syntax from the remoteRepository element in the Ant Maven tasks. For example the following XML:

<remoteRepository id="myRepo" url="scp://localhost/www/repository">
    <authentication username="..." privateKey="${user.home}/.ssh/id_dsa"/>
</remoteRepository>

Can be expressed as:

remoteRepository(id: "myRepo", url: "scp://localhost/www/repository") {
    authentication username: "...", privateKey: "${userHome}/.ssh/id_dsa"
}

By default the plugin will try to detect the protocol to use from the URL of the repository (ie "http" from "http://.." etc.), however to specify a different protocol you can do:

grails maven-deploy --repository=myRepo --protocol=webdav

The available protocols are:

  • http
  • scp
  • scpexe
  • ftp
  • webdav

maven-deploy

maven-deploy命令将Grails工程或者插件发布到远程的Maven存储库:

grails maven-deploy

上述示例的前提是你已经配置了pom.xml文件的<distributionManagement>,或者你可以通过指定远程存储库id的方式,比如:

grails maven-deploy --repository=myRepo

repository参数是存储库的'id',此'id'的详细配置位于grails-app/conf/BuildConfig.groovy或者$USER_HOME/.grails/settings.groovy文件中:

grails.project.dependency.distribution = {
    localRepository = "/path/to/my/local"
    remoteRepository(id: "myRepo", url: "http://myserver/path/to/repo")
}

配置远程存储库的语法跟Ant Maven任务的remoteRepository元素相对应,如下XML所示:

<remoteRepository id="myRepo" url="scp://localhost/www/repository">
    <authentication username="..." privateKey="${user.home}/.ssh/id_dsa"/>
</remoteRepository>

可以对应为:

remoteRepository(id: "myRepo", url: "scp://localhost/www/repository") {
    authentication username: "...", privateKey: "${userHome}/.ssh/id_dsa"
}

缺省条件下,此插件通过存储库的URL来自动检测协议的(比如"http://.."是"http"),不过你还是可以指定另外一个不同的协议的:

grails maven-deploy --repository=myRepo --protocol=webdav

支持的有效协议如下:

  • http
  • scp
  • scpexe
  • ftp
  • webdav

Groups, Artifacts and Versions

Maven defines the notion of a 'groupId', 'artifactId' and a 'version'. This plugin pulls this information from the Grails project conventions or plugin descriptor.

Projects

For applications this plugin will use the Grails application name and version provided by Grails when generating the pom.xml file. To change the version you can run the set-version command:

grails set-version 0.2

The Maven groupId will be the same as the project name, unless you specify a different one in Config.groovy:

grails.project.groupId="com.mycompany"

组,工件和版本

在Maven中,定义了'groupId','artifactId'和'version'概念,Maven插件会将Grails工程或者插件的描述转换为这些相应的定义。

工程

对于一个应用来说,当要生成pom.xml文件的时候,此插件会根据Grails应用提供的名称和版本进行生成。要修改版本信息,可以运行set-version命令来完成:

grails set-version 0.2

缺省情况下,Maven的groupId跟其工程名称一样,不过你可以在Config.groovy中指定,比如:

grails.project.groupId="com.mycompany"

Plugins

With a Grails plugin the groupId and version are taken from the following properties in the *GrailsPlugin.groovy descriptor:

String groupId = 'myOrg'
String version = '0.1'

The 'artifactId' is taken from the plugin name. For example if you have a plugin called FeedsGrailsPlugin the artifactId will be "feeds". If your plugin does not specify a groupId then this defaults to "org.grails.plugins".

插件

对于一个Grails插件来说,其groupIdversion来自于*GrailsPlugin.groovy文件的描述属性:

String groupId = 'myOrg'
String version = '0.1'

'artifactId'来自于插件的名称。比如你有一个插件是FeedsGrailsPlugin那么其artifactId是"feeds"。如果你的插件没有指定groupId那么其缺省值为"org.grails.plugins"。