【发布时间】:2015-10-16 08:52:08
【问题描述】:
我需要使用公司构建服务器构建 Grails 3.x 应用程序, 只允许基于 Maven 的构建。
是否可以使用 maven 构建 Grails 3 应用程序并将其打包到 war,以及如何做到这一点?
【问题讨论】:
我需要使用公司构建服务器构建 Grails 3.x 应用程序, 只允许基于 Maven 的构建。
是否可以使用 maven 构建 Grails 3 应用程序并将其打包到 war,以及如何做到这一点?
【问题讨论】:
有一个 grails-maven 插件但是it doesn't works with grails 3.
我终于用gradle-maven-plugin >= 1.0.7 解决了(感谢Graeme Rocher 的建议)。
为了让 maven 构建您的 grails 应用程序,您必须:
1 - 像这样创建一个 pom.xml 文件
<?xml version="1.0"?>
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.mypackage</groupId>
<artifactId>mywebapp</artifactId>
<packaging>jar</packaging>
<version>0.0.1</version>
<name>my web app</name>
<build>
<plugins>
<plugin>
<groupId>org.fortasoft</groupId>
<artifactId>gradle-maven-plugin</artifactId>
<version>1.0.7</version>
<configuration>
<tasks>
<!-- this would effectively call "gradle war" -->
<task>war</task>
</tasks>
</configuration>
<executions>
<execution>
<!-- You can bind this to any phase you like -->
<phase>compile</phase>
<goals>
<!-- goal must be "invoke" -->
<goal>invoke</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
2 - 将 jcenter maven 存储库添加到您的 maven 配置中
最新的插件版本is available only here。
<?xml version='1.0' encoding='UTF-8'?>
<settings xsi:schemaLocation='http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd' xmlns='http://maven.apache.org/SETTINGS/1.0.0' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'>
<profiles>
<profile>
<repositories>
<repository>
<snapshots>
<enabled>false</enabled>
</snapshots>
<id>bintray-robschoening-gradle-maven-plugin</id>
<name>bintray</name>
<url>http://dl.bintray.com/robschoening/gradle-maven-plugin</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<snapshots>
<enabled>false</enabled>
</snapshots>
<id>bintray-robschoening-gradle-maven-plugin</id>
<name>bintray-plugins</name>
<url>http://dl.bintray.com/robschoening/gradle-maven-plugin</url>
</pluginRepository>
</pluginRepositories>
<id>bintray</id>
</profile>
</profiles>
<activeProfiles>
<activeProfile>bintray</activeProfile>
</activeProfiles>
</settings>
2 [Alternative] - 从源代码构建插件
git clone https://github.com/if6was9/gradle-maven-plugin.git
## build and install it locally
mvn install
3 - 运行 mvn package 以构建您的 grails 应用程序
maven 插件会自动执行 grails 应用程序中的 gradle 包装器来构建它。应用程序战争将位于build/libs 目录内。
【讨论】: