在 Grails 2.2.x 之前,我已经能够使用 Maven 创建 grails 项目并将它们包含在 Maven Ear 项目中,并且一切正常。Grails 2.2.x 中的新 pom.xml 已将打包类型更改为“grails-app”,这导致了一些新问题。旧的包装类型是“战争”,效果很好。
有没有人遇到同样的问题?有解决方法吗?
这是我项目的结构。
TestProject
|-pom.xml
|-TestEar
| \pom.xml
|-TestGrailsApp
\pom.xml
测试项目 pom.xml
<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.0http://maven.apache.org/xsd/maven-4.0.0.xsd";>
<modelVersion>4.0.0</modelVersion>
<groupId>test</groupId>
<artifactId>testProject</artifactId>
<version>0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<name>Test Project</name>
<modules>
<module>TestGrailsApp</module>
<module>TestEar</module>
</modules>
</project>
TestGrailsApp pom.xml
4.0.0 测试 testGrailsApp grails-app 0.1-SNAPSHOT 测试 Grails 应用
<parent>
<groupId>test</groupId>
<artifactId>testProject</artifactId>
<version>0.1-SNAPSHOT</version>
</parent>
<properties>
<grails.version>2.2.1</grails.version>
</properties>
...
TestEar 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.0http://maven.apache.org/xsd/maven-4.0.0.xsd";>
<modelVersion>4.0.0</modelVersion>
<artifactId>testEar</artifactId>
<packaging>ear</packaging>
<name>Test Ear</name>
<parent>
<groupId>test</groupId>
<artifactId>testProject</artifactId>
<version>0.1-SNAPSHOT</version>
</parent>
<build>
<plugins>
<plugin>
<artifactId>maven-ear-plugin</artifactId>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
</manifest>
</archive>
<modules>
<webModule>
<groupId>test</groupId>
<artifactId>testGrailsApp</artifactId>
<contextRoot>/web</contextRoot>
</webModule>
</modules>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>test</groupId>
<artifactId>testGrailsApp</artifactId>
<type>grails-app</type>
<version>0.1-SNAPSHOT</version>
</dependency>
</dependencies>
</project>
这是尝试构建项目的结果
$ mvn install -e
错误堆栈跟踪已打开。
[INFO] Scanning for projects...
[INFO] Reactor build order:
[INFO] TestProject
[INFO] TestGrailsApp
[INFO] TestEar
[INFO] ------------------------------------------------------------------------
[INFO] Building TestProject
[INFO] task-segment: [install]
[INFO] ------------------------------------------------------------------------
[INFO] [timestamp:create {execution: default}]
[INFO] [site:attach-descriptor {execution: default-attach-descriptor}]
[INFO] [install:install {execution: default-install}]
[INFO] Installing /local2/testProject/pom.xml to /usr2/User1/.m2/repository/test/TestProject/0.1-SNAPSHOT/testProject-0.1-SNAPSHOT.pom
[INFO] ------------------------------------------------------------------------
[INFO] Building TestGrailsApp
[INFO] task-segment: [install]
[INFO] ------------------------------------------------------------------------
[INFO] [grails:validate {execution: default-validate}]
[INFO] [timestamp:create {execution: default}]
[INFO] [grails:init {execution: default-init}]
[INFO] [grails:config-directories {execution: default-config-directories}]
[INFO] [grails:maven-compile {execution: default-maven-compile}]
|Loading Grails 2.2.1
|Downloading: testGrailsApp-0.1-SNAPSHOT.pom
|Configuring classpath
|Running pre-compiled script
.
|Environment set to development
...........
[INFO] [grails:maven-test {execution: default-maven-test}]
|Loading Grails 2.2.1
|Configuring classpath
|Running pre-compiled script
.
|Environment set to test
....................
|Running 4 unit tests...
|Running 4 unit tests... 1 of 4
|Running 4 unit tests... 2 of 4
|Running 4 unit tests... 3 of 4
|Running 4 unit tests... 4 of 4
|Completed 4 unit tests, 0 failed in 1787ms
.
|Tests PASSED - view reports in /local2/testProject/testGrailsApp/target/test-reports
[INFO] [grails:maven-grails-app-war {execution: default-maven-grails-app-war}]
|Loading Grails 2.2.1
|Configuring classpath
|Running pre-compiled script
.
|Environment set to prod
.................................
|Packaging Grails application
................
|Compiling 3 GSP files for package [testGrailsApp]
...
|Building WAR file
......................................
|Done creating WAR target/testGrailsApp-0.1-SNAPSHOT.war
[INFO] [grails:maven-functional-test {execution: default-maven-functional-test}]
|Loading Grails 2.2.1
|Configuring classpath
|Running pre-compiled script
.
|Environment set to test
....................
|Running 4 unit tests...
|Running 4 unit tests... 1 of 4
|Running 4 unit tests... 2 of 4
|Running 4 unit tests... 3 of 4
|Running 4 unit tests... 4 of 4
|Completed 4 unit tests, 0 failed in 1747ms
............................
|Packaging Grails application
...........................
|Tests PASSED - view reports in /local2/testProject/testGrailsApp//target/test-reports
[INFO] [install:install {execution: default-install}]
[INFO] Installing /local2/testProject/testGrailsApp/target/testGrailsApp-0.1-SNAPSHOT.war to /usr2/User1/.m2/repository/testProject/testGrailsApp/0.1-SNAPSHOT/testGrailsApp-0.1-SNAPSHOT.war
[INFO] ------------------------------------------------------------------------
[INFO] Building TestEar
[INFO] task-segment: [install]
[INFO] ------------------------------------------------------------------------
[INFO] [ear:generate-application-xml {execution: default-generate-application-xml}]
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Artifact[war:testProject:testGrailsApp] is not a dependency of the project.
[INFO] ------------------------------------------------------------------------
[INFO] Trace
org.apache.maven.BuildFailureException: Artifact[war:testProject:testGrailsApp] is not a dependency of the project.
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(DefaultLifecycleExecutor.java:715)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalWithLifecycle(DefaultLifecycleExecutor.java:556)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoal(DefaultLifecycleExecutor.java:535)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalAndHandleFailures(DefaultLifecycleExecutor.java:387)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeTaskSegments(DefaultLifecycleExecutor.java:348)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute(DefaultLifecycleExecutor.java:180)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:328)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:138)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:362)
at org.apache.maven.cli.compat.CompatibleMain.main(CompatibleMain.java:60)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.codehaus.classworlds.Launcher.launchEnhanced(Launcher.java:315)
at org.codehaus.classworlds.Launcher.launch(Launcher.java:255)
at org.codehaus.classworlds.Launcher.mainWithExitCode(Launcher.java:430)
at org.codehaus.classworlds.Launcher.main(Launcher.java:375)
Caused by: org.apache.maven.plugin.MojoFailureException: Artifact[war:testProject:testGrailsApp] is not a dependency of the project.
at org.apache.maven.plugin.ear.AbstractEarModule.resolveArtifact(AbstractEarModule.java:114)
at org.apache.maven.plugin.ear.WebModule.resolveArtifact(WebModule.java:78)
at org.apache.maven.plugin.ear.AbstractEarMojo.execute(AbstractEarMojo.java:200)
at org.apache.maven.plugin.ear.GenerateApplicationXmlMojo.execute(GenerateApplicationXmlMojo.java:84)
at org.apache.maven.plugin.DefaultPluginManager.executeMojo(DefaultPluginManager.java:490)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(DefaultLifecycleExecutor.java:694)
... 17 more
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 51 seconds
[INFO] Finished at: Wed Mar 27 11:20:40 PDT 2013
[INFO] Final Memory: 39M/315M
[INFO] ------------------------------------------------------------------------