为什么 maven-deploy-plugin 无法解析我的自定义系统属性?

发布于 2024-12-07 10:04:51 字数 3373 浏览 0 评论 0原文

我正在使用 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.

Why is the maven-antrun-plugin能够解析我的自定义系统属性,而 maven-deploy-plugin 不是?

I'm using the gmaven-plugin to set a custom system property in my POM. This seems to work, as I'm able to successfully echo the property using the maven-antrun-plugin; however, the maven-deploy-plugin seems completely unaware of the property and is unable to resolve it.

Relevant portion of the 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>

When I run this with mvn clean install deploy:deploy-file, I get the following error:

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.

Why is the maven-antrun-plugin able to resolve my custom system property, while the maven-deploy-plugin is not?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

﹂绝世的画 2024-12-14 10:04:51

我不确定,但我相信 ${...} 占位符语法只能解析项目属性。我相信系统属性是在构建过程中的某个时刻添加到项目属性中的,这就是为什么系统属性以这种方式可用,但稍后在构建中添加的系统属性将不可用。您应该将该属性添加到项目属性

I'm not sure, but I believe that the ${...} placeholder syntax can only resolve project properties. I believe the system properties are added to the project properties at a point in the build, which is why system properties are available in this way, but a system property added later in the build won't be available. You should add the property to the project properties instead.

冬天旳寂寞 2024-12-14 10:04:51

我不确定这是如何相关的,但我最近发现了使用 ${...} 语法和 gmaven-plugin 时遇到的问题。在我的插件中,我为构建生成了一个 FinalName。 pom 的这一部分看起来像:

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

然后,在 maven 部分中,我有类似的内容:

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

pom 是为了一场战争。当我运行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]

经过多次绞尽脑汁,我终于弄清楚如何解决问题。 myvar 需要声明为String

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

I'm not sure how this is related, but I recently figured out a problem I was having using the ${...} syntax and the gmaven-plugin. In my plugin I was generating a finalName for the build. This part of the pom looks like:

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

Then, in the maven <source> section I had something like:

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

The pom was for a war. When I ran maven, the output was always:

[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]

After much head scratching I finally figured out how to solve the problem. myvar needed to be declared as a String!

String myvar = "prefix${someothervar}suffix"
project.properties['my.final.name'] = myvar
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文