无法使maven2配置文件正常工作

时间:2009-07-13 08:17:09

标签: maven-2

我在pom.xml中定义了以下配置文件:

  <profiles>
    <profile>
      <id>dev</id>
      <build>
        <plugins>
          <plugin>
            <artifactId>maven-antrun-plugin</artifactId>
            <executions>
              <execution>
                <phase>dev</phase>
                <goals>
                  <goal>run</goal>
                </goals>
                <configuration>
                  <tasks>
                    <delete file="src/main/application/META-INF/data-sources.xml"/>
                    <copy file="src/main/resources/data-sources-dev.xml" tofile="src/main/application/META-INF/data-sources.xml"/>
                  </tasks>
                </configuration>
              </execution>
            </executions>
          </plugin>
          <plugin>
            <artifactId>maven-surefire-plugin</artifactId>
            <configuration>
              <skip>true</skip>
            </configuration>
          </plugin>
        </plugins>
      </build>
    </profile>
  </profiles>

问题是它似乎不起作用!

mvn help:effective-pom -P dev

也回应了个人资料。

然而,如果我这样做

mvn -X -Pdev install

删除/复制部分在日志中不可见。

2 个答案:

答案 0 :(得分:3)

phase没有名称为dev的{​​{1}}。请指定correct phase

答案 1 :(得分:1)

我只是将你的配置复制粘贴到一个基本的pom中,它运行得很好。你确定它没有出现在配置和配置文件中吗?如果您将输出重定向到文件并搜索“antrun”,我怀疑您会看到它是在有效pom的构建部分中声明的。

您的antrun插件配置需要绑定到其打包类型的有效阶段才能执行。如果您希望内容在jar中可用(假设jar包装),则需要在包阶段之前。我建议 process-resources

所以改变:

<phase>dev</phase>

为:

<phase>process-resources</phase>