[英]Maven does not resolve a local Grails plug-in
我的目標是采用Grails Web應用程序,並使用Maven將其構建到Web ARchive(WAR文件)中,關鍵是它必須填充“ plugins”文件夾,而不能實時訪問Internet 。 一個“開箱即用”的Grails Web應用程序將已經在plugins文件夾中填充了JAR文件,但是maven構建腳本應負責填充它,就像對任何傳統WAR項目(例如WEB-INF / lib /如果是空的)
使用Maven 2.0.10和org.grails:grails-maven-plugin:1.0在Grails 1.1上執行mvn grails:run-app
時,這是一個錯誤。 (執行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.
構建機器無法訪問Internet,並且必須使用內部/企業存儲庫,因此此錯誤僅表示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文件的副本,該文件是使用原型生成的。
<?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”。 您還應該能夠從Grails插件配置中刪除<executions>
塊。
現在,POM將允許您構建和打包Hibernate插件,但是仍然需要部署它。 因此,將本地存儲庫添加到POM的分發管理中,然后運行mvn deploy
。 完成后,您應該可以將插件作為標准依賴項添加到應用程序的POM中。
這項工作很辛苦,但至少每個插件版本您只需要做一次!
我能夠想出一種解決方法來啟動並運行。
這需要在本地安裝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>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.