gpt4 book ai didi

java - Maven 插件没有在我想要的地方运行

转载 作者:塔克拉玛干 更新时间:2023-11-01 22:27:30 26 4
gpt4 key购买 nike

我有一个 Maven 项目,我想在事情发生时从文件加载属性。我有 codehaus properties-maven-plugin,我需要它自动运行。

如果我运行 mvn testmvn compile,任务插件会加载属性文件。

我在输出中看到了这个:[信息] --- properties-maven-plugin:1.0-alpha-2:read-project-properties (default)...---
当我运行 mvn flyway:init 时,我没有看到它运行并且没有加载属性。

这是 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>net.foo</groupId>
<artifactId>workflow</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>Foo Framework</name>
<description>Foo framework</description>
<properties>
<postgre.version>9.1-901.jdbc4</postgre.version>
<flyway.version>2.2.1</flyway.version>
</properties>
<dependencies>
<dependency>
<groupId>postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>${postgre.version}</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>com.googlecode.flyway</groupId>
<artifactId>flyway-maven-plugin</artifactId>
<version>2.2.1</version>
<configuration>
<url>${url}</url>
<user>${user}</user>
<password>${pass}</password>
<locations>
<location>classpath:sql/pgsql</location>
</locations>
</configuration>
<dependencies>
<dependency>
<groupId>postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>${postgre.version}</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>properties-maven-plugin</artifactId>
<version>1.0-alpha-2</version>
<executions>
<execution>
<phase>initialize</phase>
<goals>
<goal>read-project-properties</goal>
</goals>
<configuration>
<files>
<file>src/main/resources/db.properties</file>
</files>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

任何人都可以建议我可以做什么,或者我可以阅读一些文档来完成这项工作吗?我已经阅读了大量的 Maven 文档,但似乎无法很好地理解它以实现这一目标。我以为我这里有什么可以让它在 initialize 阶段运行,但显然不是......

最佳答案

你很接近。使用阶段运行 Maven 和使用目标运行 Maven 是有区别的。从快速回顾 Maven lifecycle documentation 开始.

当您运行mvn compile 时,Maven 会运行绑定(bind)到编译阶段的所有目标,以及绑定(bind)到早期阶段的所有目标。您已将 properties:read-project-properties 目标绑定(bind)到 initialize 阶段。 initialize 是第一阶段之一,因此 read-project-properties 在 compiletest 或使用任何后续阶段时执行在命令中。

当您运行 mvn flyway:init 时,您只是在运行一个目标,而不是整个生命周期。因此,唯一与该命令一起运行的是 flyway-maven-plugin 的初始目标,没有别的。

如果您希望这两个目标一起运行,您可以尝试将 flyway:init 目标绑定(bind)到 initialize 阶段(如果这不是默认设置;我可以阅读插件的文档无法判断)。然后,mvn initialize 将运行两者。

如果您不想将 flyway:init 绑定(bind)到一个阶段,那么您可以使用 mvn flyway:init initialize 显式运行这两个目标。

关于java - Maven 插件没有在我想要的地方运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20157652/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com