1

gmaven-plugin を使用して、POM でカスタム システム プロパティを設定しています。maven-antrun-plugin を使用してプロパティを正常にエコーできるため、これは機能しているようです。ただし、maven-deploy-plugin はプロパティをまったく認識していないようで、解決できません。

POM の関連部分:

<build>
    <plugins>
        <plugin>
            <groupId>org.codehaus.gmaven</groupId>
            <artifactId>gmaven-plugin</artifactId>
            <version>1.3</version>
            <executions>
                <execution>
                    <phase>generate-sources</phase>
                    <goals>
                        <goal>execute</goal>
                    </goals>
                    <configuration>
                        <source>
                            System.setProperty("nodotsversion", "${env.PATCH_VERSION}".replace('.', ''))
                        </source>
                    </configuration>
                </execution>
            </executions>
        </plugin>

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-antrun-plugin</artifactId>
            <version>1.6</version><!-- 1.2 in central -->
            <executions>
                <execution>
                    <id>compile</id>
                    <phase>compile</phase>
                    <configuration>
                        <target>
                            <echo message="${nodotsversion}" />     
                        </target>
                    </configuration>
                    <goals>
                        <goal>run</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-deploy-plugin</artifactId>
            <version>2.6</version>
            <goals>
                <goal>deploy-file</goal>
            </goals>
            <configuration>
                <repositoryId>artifactory</repositoryId>
                <packaging>sql</packaging>
                <generatePom>true</generatePom>
                <url>${project.distributionManagement.snapshotRepository.url}</url>
                <groupId>com.company.product</groupId>
                <artifactId>patch${nodotsversion}</artifactId>
                <version>1.0.0-SNAPSHOT</version>
                <file>${WORKSPACE}/myfile.sql</file>
            </configuration>
        </plugin>
    </plugins>
</build>

これを で実行するとmvn clean install deploy:deploy-file、次のエラーが発生します。

Caused by: org.apache.maven.plugin.MojoExecutionException: The artifact information is incomplete or not valid:
  [0]  'artifactId' with value 'patch${nodotsversion}' does not match a valid id pattern.

maven-antrun-plugin ではカスタム システム プロパティを解決できるのに、maven-deploy-plugin では解決できないのはなぜですか?

4

2 に答える 2

2

よくわかりませんが、${...}プレースホルダー構文ではプロジェクトのプロパティしか解決できないと思います。システムプロパティはビルドのある時点でプロジェクトプロパティに追加されると思います。そのため、システムプロパティはこの方法で使用できますが、ビルドの後半で追加されたシステムプロパティは使用できません。代わりに、プロジェクトのプロパティにプロパティを追加する必要があります。

于 2011-09-30T04:24:15.523 に答える
0

これがどのように関連しているかはわかりませんが、最近、${...}構文と gmaven-plugin を使用して発生していた問題を突き止めました。私のプラグインでは、ビルドの finalName を生成していました。pom のこの部分は次のようになります。

<build>
   <finalName>${my.final.name}</finalName>

次に、maven<source>セクションに次のようなものがありました。

def myvar = "prefix${someothervar}suffix"
project.properties['my.final.name'] = myvar

ポンは戦争用でした。Maven を実行すると、出力は常に次のようになりました。

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-war-plugin:2.1.1:war (default-war) on project myservice: The parameters 'warName' for goal org.apache.maven.plugins:maven-war-plugin:2.1.1:war are missing or invalid -> [Help 1]

何度も頭を悩ませた後、ようやく問題を解決する方法を見つけました。Stringmyvarとして宣言する必要がありました!

String myvar = "prefix${someothervar}suffix"
project.properties['my.final.name'] = myvar
于 2014-04-16T22:02:24.530 に答える