我的目标是使用 Maven 将 Grails Web 应用程序构建到 Web ARchive(WAR 文件)中,关键是 它必须填充“插件”文件夹而不能实时访问互联网 .一个“开箱即用”的 Grails webapp 已经在 plugins 文件夹中填充了 JAR 文件,但是 maven 构建脚本应该负责填充它,就像它对任何传统的 WAR 项目(例如 WEB-INF/lib/如果它是空的)
这是执行 mvn grails:run-app
时的错误。 Grails 1.1 使用 Maven 2.0.10 和 org.grails:grails-maven-plugin:1.0。 (做 GORM 需要这个“hibernate-1.1”插件。)
[INFO] [grails:run-app]
Running pre-compiled script
Environment set to development
Plugin [hibernate-1.1] not installed, resolving..
Reading remote plugin list ...
Error reading remote plugin list [svn.codehaus.org], building locally...
Unable to list plugins, please check you have a valid internet connection: svn.codehaus.org
Reading remote plugin list ...
Error reading remote plugin list [plugins.grails.org], building locally...
Unable to list plugins, please check you have a valid internet connection: plugins.grails.org
Plugin 'hibernate' was not found in repository. If it is not stored in a configured repository you will need to install it manually. Type 'grails list-plugins' to find out what plugins are available.
构建机器无法访问互联网,必须使用内部/企业存储库,所以这个错误只是说 maven 无法在任何地方找到所需的工件。这种依赖关系已经包含在本地安装的 Grails 软件中,所以我只需要弄清楚如何让我的 POM 文件将该 ZIP 文件解包到我的 webapp 的“插件”文件夹中。
我已经尝试将插件手动安装到我的本地存储库并使其成为 POM.xml 中的显式依赖项,但它仍然无法被识别。也许您不能像标准 maven 引用一样下拉 grails 插件?
mvn install:install-file -DgroupId=org.grails -DartifactId=grails-hibernate -Dversion=1.1 -Dpackaging=zip -Dfile=%GRAILS_HOME%/plugins/grails-hibernate-1.1.zip
我可以从命令行手动设置 Grails webapp,从而正确创建本地 ./plugins 文件夹。这是朝着正确方向迈出的一步,所以问题可能是:如何将这个目标纳入我的 POM?
mvn grails:install-plugin -DpluginUrl=%GRAILS_HOME%/plugins/grails-hibernate-1.1.zip
这是我的 POM.xml 文件的副本,它是使用原型(prototype)生成的。
<?xml version="1.0" encoding="UTF-8"?>
<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>com.samples</groupId>
<artifactId>sample-grails</artifactId>
<packaging>war</packaging>
<name>Sample Grails webapp</name>
<properties>
<sourceComplianceLevel>1.5</sourceComplianceLevel>
</properties>
<version>0.0.1-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.grails</groupId>
<artifactId>grails-crud</artifactId>
<version>1.1</version>
</dependency>
<dependency>
<groupId>org.grails</groupId>
<artifactId>grails-gorm</artifactId>
<version>1.1</version>
</dependency>
<dependency>
<groupId>opensymphony</groupId>
<artifactId>oscache</artifactId>
<version>2.4</version>
<exclusions>
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
<exclusion>
<groupId>javax.jms</groupId>
<artifactId>jms</artifactId>
</exclusion>
<exclusion>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>hsqldb</groupId>
<artifactId>hsqldb</artifactId>
<version>1.8.0.7</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.5.6</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<!--
<dependency>
<groupId>org.grails</groupId>
<artifactId>grails-hibernate</artifactId>
<version>1.1</version>
<type>zip</type>
</dependency>
-->
</dependencies>
<build>
<pluginManagement />
<plugins>
<plugin>
<groupId>org.grails</groupId>
<artifactId>grails-maven-plugin</artifactId>
<version>1.0</version>
<extensions>true</extensions>
<executions>
<execution>
<goals>
<goal>init</goal>
<goal>maven-clean</goal>
<goal>validate</goal>
<goal>config-directories</goal>
<goal>maven-compile</goal>
<goal>maven-test</goal>
<goal>maven-war</goal>
<goal>maven-functional-test</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>${sourceComplianceLevel}</source>
<target>${sourceComplianceLevel}</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
最佳答案
这是一个棘手的问题。我打算建议使用 Grails 1.3,它允许您从与 Maven 兼容的存储库中提取 Grails 插件,但我认为这对 Maven 没有帮助(目前)。
所以,我将建议一些我自己没有尝试过但可能有用的东西。我有一些信心,因为我在 Grails Maven 插件中编写了相关代码;)但不能保证。
有了这个,让我们开始吧。首先,您需要获取相关 Grails 插件的代码。例如,您可以从这里获取 Hibernate:
http://svn.codehaus.org/grails/trunk/grails-plugins/grails-hibernate/tags/RELEASE_1_1/
您只需要一份代码副本,因此只读结帐就可以了。
获得代码后,运行
mvn grails:create-pom -DgroupId=org.grails.plugins
从插件项目的根目录。这将生成一个 POM。接下来,您需要编辑 POM 并将打包更改为“grails-plugin”。您还应该能够删除 <executions>
来自 Grails 插件配置的 block 。POM 现在将允许您构建和打包 Hibernate 插件,但您仍然必须部署它。因此,将本地存储库添加到 POM 的分发管理并运行
mvn deploy
.完成后,您应该能够将该插件作为标准依赖项添加到应用程序的 POM 中。这是一项艰巨的工作,但至少每个版本的插件只需执行一次!
关于maven-2 - Maven 不解析本地 Grails 插件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2908964/