【问题标题】:Upgrading maven 2 to maven 3将 maven 2 升级到 maven 3
【发布时间】:2013-07-12 04:00:42
【问题描述】:

当我升级 maven 时,属性插件有问题:

                    <groupId>org.codehaus.mojo</groupId>
                    <artifactId>properties-maven-plugin</artifactId>

在我的 pom 中我定义了属性:

<?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.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <artifactId>...</artifactId>
    <groupId>...</groupId>
    <packaging>war</packaging>
    <version>1.0.10-SNAPSHOT</version>
    <name>...</name>   



<properties>

    <!-- application -->
    <appname>appname1</appname>

</properties>

<build>
   ... // here I dont have properties plugin because I dont need them
<plugin>
                <artifactId>maven-war-plugin</artifactId>
                <configuration>
                    <warName>${appname}</warName> // here is stil name in pom
                    <webResources>
                        <resource>
                            <filtering>true</filtering>
                            <directory>src/main/webapp</directory>
                        </resource>
                    </webResources>
                </configuration>
            </plugin>
...
</build>

<profiles>      

    <profile>
        <id>config</id>
        <activation>
            <property>
                <name>config</name>
            </property>
        </activation>
        <properties>
            <config>${basedir}/../config/${config}/build.properties</config>
        </properties>
        <build>
            <plugins>                   
                <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>${config}</file>
                                </files>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>                    
            </plugins>
        </build>
    </profile>

</profiles>

<dependencies>
...
</dependencies>

</project>

然后我有个人资料:

<profile>
            <id>config</id>
            <activation>
                <property>
                    <name>config</name>
                </property>
            </activation>
            <properties>
                <konfig>${basedir}/../config/${config}/build.properties</konfig>
            </properties>
            <build>
                <plugins>                    
                    <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>${konfig}</file>
                                    </files>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>                    
                </plugins>
            </build>
        </profile>

我可以在其中指定另一个具有属性的文件:

文件包含:

 appname=appname2

所以当我运行 mvn 时,logis 是从 pom.xml 获取的。如果使用配置文件,它应该使用配置文件中的属性。这适用于 maven 2,但 maven 3 仍然从 pom 获取属性。有办法解决吗?

这里:http://mojo.codehaus.org/properties-maven-plugin/read-project-properties-mojo.html 是这样写的:

属性:

Requires a Maven 2.0 project to be executed.

表示maven 3不支持这个插件?

【问题讨论】:

  • 你能显示完整的 pom,因为我怀疑这是基于 properties-maven-plugin。
  • 我无法显示整个 pom,但我对其进行了编辑并仅显示重要部分。有趣的是,当我从 pom 中删除属性时它可以工作,所以重写属性只是有问题
  • 我已经用 maven 3.0.3 进行了检查,它运行良好。你可以发布 pom 文件吗...
  • 我使用的是 3.0.4。我只是发布pom。你没看到?
  • 你想设置什么样的属性查看build.properties?

标签: maven


【解决方案1】:

从 Maven 2 迁移到 Maven 3 时要小心,因为 Maven 2 会在启动时加载所有依赖项,而 Maven 3 会按需加载它们。因此,在 Maven 3 中运行的构建将在运行 Maven 2 的构建框上中断。经验教训。

【讨论】:

    猜你喜欢
    • 2012-05-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-04-22
    • 1970-01-01
    • 2019-07-15
    • 2013-12-01
    • 1970-01-01
    相关资源
    最近更新 更多