Grails应用程序包使用maven进行战争

时间:2015-10-16 08:52:09

标签: maven grails gradle

我需要使用公司构建服务器构建Grails 3.x应用程序, 只允许基于maven的构建。

是否可以使用maven构建和打包Grails 3应用程序,以及如何执行此操作?

1 个答案:

答案 0 :(得分:1)

有一个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 [替代方案] - 从来源构建插件

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目录中。