如果python脚本出现任何错误,如何使maven构建失败

2024-04-28 09:47:32 发布

您现在位置:Python中文网/ 问答频道 /正文

我在maven项目中使用python脚本,如果python脚本出现任何错误,我希望生成失败并显示正确的错误消息

插件里有什么东西吗。如果python出现错误,我们可以从中失败构建并显示日志记录错误

这是我的pom.xml

<build>
    <plugins>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>exec-maven-plugin</artifactId>
            <version>1.6.0</version>
            <executions>
                <execution>
                    <configuration>
                        <executable>python</executable>
                        <workingDirectory>src/main/resources/</workingDirectory>
                        <arguments>
                            <argument>my.py</argument>
                        </arguments>
                    </configuration>
                    <id>python_build</id>
                    <phase>generate-resources</phase>
                    <goals>
                        <goal>exec</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

这是我的python脚本my.py

import logging

name = "Amit"
age = 24
if name != "Amit":
    logging.error("name is not matching")

if age != 24:
    logging.error("age is not matching")

Tags: namebuild脚本ageversionlogging错误plugins
1条回答
网友
1楼 · 发布于 2024-04-28 09:47:32

如果要引发错误,请添加exit

import logging

name = "Amit"
age = 24
if name != "Amit":
    logging.error("name is not matching")
    exit(1)

if age != 24:
    logging.error("age is not matching")
    exit(1)

相关问题 更多 >