Maven 无法解析本地 Grails 插件

发布于 2024-09-03 03:24:41 字数 6346 浏览 2 评论 0原文

我的目标是使用 Maven 将 Grails Web 应用程序构建到 Web ARchive(WAR 文件)中,关键是它必须填充“plugins”文件夹而无需实时访问互联网。一个“开箱即用”的 Grails web 应用程序已经有用 JAR 文件填充的插件文件夹,但是 maven 构建脚本应该负责填充它,就像它对任何传统的 WAR 项目(例如 WEB-INF/lib/如果为空)

使用 Maven 2.0.10 和 org.grails:grails-maven-plugin:1.0 执行 mvn grails:run-app 以及 Grails 1.1 时会出现错误。 (执行 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 文件解压到我的 web 应用程序的“plugins”文件夹中。

我尝试将插件手动安装到本地存储库并使其成为 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

I可以从命令行手动设置 Grails web 应用程序,这会正确创建本地 ./plugins 文件夹。这是朝着正确方向迈出的一步,所以问题可能是:如何将这个目标纳入我的 POM 中? mvn grails:install-plugin -DpluginUrl=%GRAILS_HOME%/plugins/grails-hibernate-1.1.zip

这是我的 POM.xml 文件的副本,它是使用原型生成的。

<?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>

My goal is to take a Grails web application and build it into a Web ARchive (WAR file) using Maven, and the key is that it must populate the "plugins" folder without live access to the internet. An "out of the box" Grails webapp will already have the plugins folder populated with JAR files, but the maven build script should take care of populating it, just like it does for any traditional WAR projects (such as WEB-INF/lib/ if it's empty)

This is an error when executing mvn grails:run-app with Grails 1.1 using Maven 2.0.10 and org.grails:grails-maven-plugin:1.0. (This "hibernate-1.1" plugin is needed to do GORM.)

[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.

The build machine does not have access to the internet and must use an internal/enterprise repository, so this error is just saying that maven can't find the required artifact anywhere. That dependency is already included with the stock Grails software that's installed locally, so I just need to figure out how to get my POM file to unpackage that ZIP file into my webapp's "plugins" folder.

I've tried installing the plugin manually to my local repository and making it an explicit dependency in POM.xml, but it's still not being recognized. Maybe you can't pull down grails plugins like you would a standard maven reference?
mvn install:install-file -DgroupId=org.grails -DartifactId=grails-hibernate -Dversion=1.1 -Dpackaging=zip -Dfile=%GRAILS_HOME%/plugins/grails-hibernate-1.1.zip

I can manually setup the Grails webapp from the command-line, which creates that local ./plugins folder properly. This is a step in the right direction, so maybe the question is: how can I incorporate this goal into my POM?
mvn grails:install-plugin -DpluginUrl=%GRAILS_HOME%/plugins/grails-hibernate-1.1.zip

Here is a copy of my POM.xml file, which was generated using an archetype.

<?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>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

恰似旧人归 2024-09-10 03:24:41

这是一个棘手的问题。我本来建议使用 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”。您还应该能够从 Grails 插件配置中删除 块。

POM 现在允许您构建和打包 Hibernate 插件,但您仍然需要部署它。因此,将本地存储库添加到 POM 的分发管理中并运行 mvn deploy。完成后,您应该能够将该插件添加为应用程序 POM 中的标准依赖项。

这是一项艰苦的工作,但至少每个版本的插件只需要做一次!

This is a tricky problem. I was going to suggest using Grails 1.3, which allows you to pull Grails plugins from Maven-compatible repositories, but I don't think this helps with Maven (at the moment).

So, I'm going to suggest something I haven't tried myself, but may work. I have some confidence because I wrote the relevant code in the Grails Maven plugin ;) No guarantees though.

With that out of the way, let's get started. First, you need to grab the code for the relevant Grails plugins. For example, you can get Hibernate from here:

http://svn.codehaus.org/grails/trunk/grails-plugins/grails-hibernate/tags/RELEASE_1_1/

You just need a copy of the code, so a read-only checkout will be fine.

Once you have the code, run mvn grails:create-pom -DgroupId=org.grails.plugins from the root of the plugin project. This will generate a POM. Next, you will need to edit the POM and change the packaging to "grails-plugin". You should also be able to remove the <executions> block from the Grails Plugin configuration.

The POM will now allow you to build and package the Hibernate plugin, but you still have to deploy it. So add your local repository to the POM's distribution management and run mvn deploy. Once that's done, you should be able to add the plugin as a standard dependency in your application's POM.

It's hard work, but at least you should only have to do it once per version of the plugin!

心不设防 2024-09-10 03:24:41

我能够想出一个解决方法来启动并运行。

这需要在本地安装 Grails 并设置 GRAILS_HOME。它将在 Maven“验证”阶段清除并填充项目的“插件”文件夹。 (将其插入上面的 POM 中。)

<plugins>
    <plugin>
        <artifactId>maven-antrun-plugin</artifactId>
        <executions>
            <execution>
                <phase>validate</phase>
                <goals>
                    <goal>run</goal>
                </goals>
                <configuration>
                    <tasks>
                        <!-- clear out this project's plugins folder if it exists, otherwise you will get prompted to upgrade it after re-building -->
                        <delete dir="${basedir}/plugins/" includeemptydirs="true"/>
                    </tasks>
                </configuration>
            </execution>
        </executions>
    </plugin>
    <plugin>
        <groupId>org.grails</groupId>
        <artifactId>grails-maven-plugin</artifactId>
        <version>1.0</version>
        <extensions>true</extensions>
        <executions>
            <execution>
                <id>create plugins folder</id>
                <phase>validate</phase>
                <goals>
                    <goal>install-plugin</goal>
                </goals>
                <configuration>
                <pluginUrl>${env.GRAILS_HOME}/plugins/grails-hibernate-1.1.zip</pluginUrl>
                </configuration>
            </execution>
        </executions>
    </plugin>
</plugins>

I was able to come up with a workaround just to get up and running.

This requires Grails be installed locally and that GRAILS_HOME be set. It will clear out and then populate the project's "plugins" folder during the maven "validate" phase. (Insert this into the POM above.)

<plugins>
    <plugin>
        <artifactId>maven-antrun-plugin</artifactId>
        <executions>
            <execution>
                <phase>validate</phase>
                <goals>
                    <goal>run</goal>
                </goals>
                <configuration>
                    <tasks>
                        <!-- clear out this project's plugins folder if it exists, otherwise you will get prompted to upgrade it after re-building -->
                        <delete dir="${basedir}/plugins/" includeemptydirs="true"/>
                    </tasks>
                </configuration>
            </execution>
        </executions>
    </plugin>
    <plugin>
        <groupId>org.grails</groupId>
        <artifactId>grails-maven-plugin</artifactId>
        <version>1.0</version>
        <extensions>true</extensions>
        <executions>
            <execution>
                <id>create plugins folder</id>
                <phase>validate</phase>
                <goals>
                    <goal>install-plugin</goal>
                </goals>
                <configuration>
                <pluginUrl>${env.GRAILS_HOME}/plugins/grails-hibernate-1.1.zip</pluginUrl>
                </configuration>
            </execution>
        </executions>
    </plugin>
</plugins>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文