Maven - 如何在使用 openjpa 插件时 运行 只编译一次目标

Maven - how to run compile goal only once while using openjpa plugin

当我 运行 mvn clean compile openjpa:enhance install 我注意到 compile 目标 运行ning 两次 - 一次在 openjpa:enhance 之前和之后(还有 resources), 这导致增强的 类 和 openjpa:enhance 被丢弃,因为它们被再次编译并重写。

如何更改 pom.xml 或 mvn 命令参数使其不会 运行 compile 两次,而只在 openjpa:enhance 之前一次? install 最后是必填项。

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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>registry</groupId>
    <artifactId>datalayer</artifactId>
    <version>0.0.1</version>
    <packaging>jar</packaging>

    <properties>
        <maven.compiler.target>11</maven.compiler.target>
        <maven.compiler.source>11</maven.compiler.source>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.sourceEncoding>UTF-8</project.reporting.sourceEncoding>
    </properties>

    <build>
        <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>3.8.1</version>
                </plugin>
                <plugin>
                    <groupId>org.apache.openjpa</groupId>
                    <artifactId>openjpa-maven-plugin</artifactId>
                    <version>3.1.2</version>
                    <configuration>
                        <includes>datalayer/dto/*.class</includes>
                        <addDefaultConstructor>true</addDefaultConstructor>
                        <enforcePropertyRestrictions>true</enforcePropertyRestrictions>
                    </configuration>
                    <executions>
                        <execution>
                            <id>enhancer</id>
                            <phase>process-classes</phase>
                            <goals>
                                <goal>enhance</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </pluginManagement>
    </build>

    <dependencies>
        <dependency>
            <groupId>org.apache.openjpa</groupId>
            <artifactId>openjpa</artifactId>
            <version>3.1.2</version>
        </dependency>
        <dependency>
            <groupId>org.apache.derby</groupId>
            <artifactId>derby</artifactId>
            <version>10.15.2.0</version>
        </dependency>
        <dependency>
            <groupId>org.apache.derby</groupId>
            <artifactId>derbytools</artifactId>
            <version>10.15.2.0</version>
        </dependency>
    </dependencies>
</project>

来自mvn clean compile openjpa:enhance install的输出:

[INFO] Scanning for projects...
[INFO]
[INFO] -------------------< registry:openjpaenhancingtest >--------------------
[INFO] Building openjpaenhancingtest 0.0.1
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ openjpaenhancingtest ---
[INFO] Deleting C:\Users\wortigson\Desktop\ISMatrikaBcWorkspace\Openjpa.Test\target
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ openjpaenhancingtest ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 1 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.8.1:compile (default-compile) @ openjpaenhancingtest ---
[WARNING] Can't extract module name from geronimo-jms_1.1_spec-1.1.1.jar: geronimo.jms.1.1.spec: Invalid module name: '1' is not a Java identifier
[WARNING] Can't extract module name from geronimo-jta_1.1_spec-1.1.1.jar: geronimo.jta.1.1.spec: Invalid module name: '1' is not a Java identifier
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 3 source files to C:\Users\wortigson\Desktop\ISMatrikaBcWorkspace\Openjpa.Test\target\classes
[INFO]
[INFO] --- openjpa-maven-plugin:3.1.2:enhance (default-cli) @ openjpaenhancingtest ---
88  DataLayer  INFO   [main] openjpa.Tool - Enhancer running on type "class entities.EntityPerson".
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ openjpaenhancingtest ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 1 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.8.1:compile (default-compile) @ openjpaenhancingtest ---
[WARNING] Can't extract module name from geronimo-jms_1.1_spec-1.1.1.jar: geronimo.jms.1.1.spec: Invalid module name: '1' is not a Java identifier
[WARNING] Can't extract module name from geronimo-jta_1.1_spec-1.1.1.jar: geronimo.jta.1.1.spec: Invalid module name: '1' is not a Java identifier
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 3 source files to C:\Users\wortigson\Desktop\ISMatrikaBcWorkspace\Openjpa.Test\target\classes
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ openjpaenhancingtest ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 0 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.8.1:testCompile (default-testCompile) @ openjpaenhancingtest ---
[WARNING] Can't extract module name from geronimo-jta_1.1_spec-1.1.1.jar: geronimo.jta.1.1.spec: Invalid module name: '1' is not a Java identifier
[WARNING] Can't extract module name from geronimo-jms_1.1_spec-1.1.1.jar: geronimo.jms.1.1.spec: Invalid module name: '1' is not a Java identifier
[INFO] Changes detected - recompiling the module!
[INFO]
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ openjpaenhancingtest ---
[INFO]
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ openjpaenhancingtest ---
[INFO] Building jar: C:\Users\wortigson\Desktop\ISMatrikaBcWorkspace\Openjpa.Test\target\openjpaenhancingtest-0.0.1.jar
[INFO]
[INFO] --- maven-install-plugin:2.4:install (default-install) @ openjpaenhancingtest ---
[INFO] Installing C:\Users\wortigson\Desktop\ISMatrikaBcWorkspace\Openjpa.Test\target\openjpaenhancingtest-0.0.1.jar to C:\Users\wortigson\.m2\repository\registry\openjpaenhancingtest[=12=].0.1\openjpaenhancingtest-0.0.1.jar
[INFO] Installing C:\Users\wortigson\Desktop\ISMatrikaBcWorkspace\Openjpa.Test\pom.xml to C:\Users\wortigson\.m2\repository\registry\openjpaenhancingtest[=12=].0.1\openjpaenhancingtest-0.0.1.pom
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS

您需要将 openjpa:enhance 添加到 POM 本身。那你就 运行 mvn clean install.