首页 > 解决方案 > Maven:cvc-complex-type.2.4.a:发现以元素“插件”开头的无效内容

问题描述

我对 Maven pom.xml 配置不是很好。

对于 Corda (Blockchain) Bootcamp 示例,我正在尝试配置一个 Eclipse 项目以与 Java 和 Kotlin 一起使用,但我面临以下错误消息:

cvc-complex-type.2.4.a: Invalid content was found starting with element 'plugin'. 
One of '{
    "http://maven.apache.org/POM/4.0.0":parent, 
    "http://maven.apache.org/POM/4.0.0":packaging, 
    "http://maven.apache.org/POM/4.0.0":name, 
    "http://maven.apache.org/POM/4.0.0":description, 
    "http://maven.apache.org/POM/4.0.0":url, 
    "http://maven.apache.org/POM/4.0.0":prerequisites, 
    "http://maven.apache.org/POM/4.0.0":issueManagement, 
    "http://maven.apache.org/POM/4.0.0":ciManagement, 
    "http://maven.apache.org/POM/4.0.0":inceptionYear, 
    "http://maven.apache.org/POM/4.0.0":mailingLists, 
    "http://maven.apache.org/POM/4.0.0":developers, 
    "http://maven.apache.org/POM/4.0.0":contributors, 
    "http://maven.apache.org/POM/4.0.0":licenses, 
    "http://maven.apache.org/POM/4.0.0":scm, 
    "http://maven.apache.org/POM/4.0.0":organization, 
    "http://maven.apache.org/POM/4.0.0":profiles, 
    "http://maven.apache.org/POM/4.0.0":modules, 
    "http://maven.apache.org/POM/4.0.0":repositories, 
    "http://maven.apache.org/POM/4.0.0":pluginRepositories, 
    "http://maven.apache.org/POM/4.0.0":dependencies, 
    "http://maven.apache.org/POM/4.0.0":reports, 
    "http://maven.apache.org/POM/4.0.0":reporting, 
    "http://maven.apache.org/POM/4.0.0":dependencyManagement, 
    "http://maven.apache.org/POM/4.0.0":distributionManagement
}' is expected.

这是整个 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.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

    <modelVersion>4.0.0</modelVersion>
    <groupId>r3</groupId>
    <artifactId>CordaAppBootCamp</artifactId>
    <version>0.0.1-SNAPSHOT</version>

    <properties>
        <java.version>1.8</java.version>
        <kotlin.version>1.2.51</kotlin.version>
    </properties>

    <build>
        <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>3.1</version>
                    <configuration>
                        <source>${java.version}</source>
                        <target>${java.version}</target>
                    </configuration>
                </plugin>

                <plugin>
                    <groupId>org.jetbrains.kotlin</groupId>
                    <artifactId>kotlin-maven-plugin</artifactId>
                    <version>${kotlin.version}</version>
                    <executions>
                        <execution>
                            <id>default-compile</id>
                            <phase>none</phase>
                        </execution>
                        <execution>
                            <id>default-testCompile</id>
                            <phase>none</phase>
                        </execution>
                        <execution>
                            <id>java-compile</id>
                            <phase>compile</phase>
                            <goals>
                                <goal>compile</goal>
                            </goals>
                        </execution>
                        <execution>
                            <id>java-test-compile</id>
                            <phase>test-compile</phase>
                            <goals>
                                <goal>testCompile</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </pluginManagement>
    </build>

    <dependencies>
        <dependency>
            <groupId>org.jetbrains.kotlin</groupId>
            <artifactId>kotlin-stdlib-jdk8</artifactId>
            <version>${kotlin.version}</version>
        </dependency>
    </dependencies>

</project>

我究竟做错了什么?

我是在这个 Baeldung 帖子中这样做的:

https://www.baeldung.com/kotlin-maven-java-project

它有更多的问题信息。其中一些我通过使用<pluginManagement>标签解决了

标签: javaeclipsemavenkotlincorda

解决方案


看看较新版本的 Bootcamp cordapp,gradle 现在为您处理所有这些,因此您无需担心自己的依赖关系。

https://github.com/corda/bootcamp-cordapp

另请注意,推荐的 IDE 实际上是 IntelliJ IDEA,不再是 eclipse。(来源:https ://docs.corda.net/docs/corda-os/4.4/getting-set-up.html )


推荐阅读