【问题标题】:error when including dependency within the plugin under execution in maven在maven中执行的插件中包含依赖项时出错
【发布时间】:2015-06-20 12:13:33
【问题描述】:

如果我直接执行 mvn 目标 mvn hibernate3:hbm2java,我有以下 pom.xml。我现在想在generate-entity 阶段让它成为执行的一部分。我在插件中包含了一些依赖项。

这是工作的 pom。

   <plugins>
         <plugin>
           <groupId>org.codehaus.mojo</groupId>
           <artifactId>hibernate3-maven-plugin</artifactId>
           <version>2.2</version>
             <configuration>
               <components>
                 <component>
                   <name>hbm2java</name>
                   <implementation>jdbcconfiguration</implementation>
                   <outputDirectory>src/main/java</outputDirectory>
                 </component>
               </components>
               <componentProperties>
                 <revengfile>src/main/resources/reveng.xml</revengfile>
                 <propertyfile>src/main/resources/hibernate.properties</propertyfile>
                 <packagename>com.whatever.domain</packagename>
                 <jdk7>true</jdk7>
                 <ejb3>true</ejb3>
               </componentProperties>
             </configuration>
             <dependencies>
               <dependency>
                 <groupId>cglib</groupId>
                 <artifactId>cglib-nodep</artifactId>
                 <version>2.2.2</version>
               </dependency>
               <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>5.1.22</version>
        </dependency>
             </dependencies>
           </plugin>
        </plugins>

当我执行 mvn hibernate3:hbm2java 时,这会按预期工作。

但我在 pom.xml 中包含了执行部分。现在 Eclipse 用这个错误消息提示我

cvc-complex-type.2.4.a: Invalid content was found starting with element 'dependencies'. One of '{"http:// maven.apache.org/POM/4.0.0":inherited}' is expected.

这是修改后的 pom.xml,在 dependencies block 内部插件附近存在问题

<plugins>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>hibernate3-maven-plugin</artifactId>
                <version>2.2</version>
                <executions>
                    <execution>
                        <id>generate-entity</id>
                        <phase>generate-entity</phase>
                        <goals>
                            <goal>hbm2ddl</goal>
                        </goals>
                        <configuration>
                            <components>
                                <component>
                                    <name>hbm2hbmxml</name>
                                    <implementation>jdbcconfiguration</implementation>
                                    <outputDirectory>src/main/java</outputDirectory>
                                </component>
                                <component>
                                    <name>hbm2java</name>
                                    <implementation>jdbcconfiguration</implementation>
                                    <outputDirectory>src/main/java</outputDirectory>
                                </component>
                            </components>
                            <componentProperties>
                                <revengfile>src/main/resources/reveng.xml</revengfile>
                                <propertyfile>src/main/resources/hibernate.properties</propertyfile>
                                <packagename>com.whatever.domain</packagename>
                                <jdk7>true</jdk7>
                                <ejb3>true</ejb3>
                            </componentProperties>
                        </configuration>
                        <dependencies> --- Eclipse shows errors here
                            <dependency>
                                <groupId>cglib</groupId>
                                <artifactId>cglib-nodep</artifactId>
                                <version>2.2.2</version>
                            </dependency>
                            <dependency>
                                <groupId>mysql</groupId>
                                <artifactId>mysql-connector-java</artifactId>
                                <version>5.1.22</version>
                            </dependency>
                        </dependencies>
                    </execution>
                </executions>
            </plugin>
        </plugins>

【问题讨论】:

    标签: hibernate maven maven-3 maven-plugin


    【解决方案1】:

    正如“Guide to Configuring Plug-ins: Using the dependencies Tag”中提到的,dependencies 标签仅在 plugin 级别可用,而不在 execution 级别,如下例所示:-

    <build>
        <plugins>
            <plugin>
                <groupId>some-group</groupId>
                <artifactId>some-artifact</artifactId>
                <version>some-version</version>
                ...
                <dependencies>
                    <dependency>
                        <groupId>some-dependency-group</groupId>
                        <artifactId>some-dependency-artifact</artifactId>
                        <version>some-dependency-version</version>
                    </dependency>
                </dependencies>
            </plugin>
        </plugins>
    </build>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-04-26
      • 1970-01-01
      • 2011-11-07
      • 1970-01-01
      • 2017-07-29
      相关资源
      最近更新 更多