Maven 可以变得不那么冗长吗?

发布于 2024-07-04 01:37:18 字数 152 浏览 11 评论 0原文

Maven 输出了太多符合我口味的输出行(我喜欢 Unix 方式:没有消息就是好消息)。

我想删除所有 [INFO] 行,但我找不到任何提及控制 Maven 详细程度的参数或配置设置。

有没有类似LOG4J的方法来设置日志级别?

Maven spews out far too many lines of output to my taste (I like the Unix way: no news is good news).

I want to get rid of all [INFO] lines, but I couldn't find any mention of an argument or config settings that controls the verbosity of Maven.

Is there no LOG4J-like way to set the log level?

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

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

发布评论

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

评论(9

幼儿园老大 2024-07-11 01:37:18

您可以尝试 -q 开关

-q,--quiet 安静输出 - 仅显示错误

You can try the -q switch.

-q,--quiet Quiet output - only show errors

掐死时间 2024-07-11 01:37:18

如上所述的 -q 就是您所需要的。 另一种选择可能是:

-B,--批处理模式
以非交互(批处理)模式运行
如果您需要在非交互式持续集成环境中运行 Maven,则批处理模式至关重要。 当以非交互模式运行时,Maven将永远不会停止接受用户的输入。 相反,当需要输入时,它将使用合理的默认值。

并且还将输出消息或多或少地减少到必需品。

-q as said above is what you need. An alternative could be:

-B,--batch-mode
Run in non-interactive (batch) mode
Batch mode is essential if you need to run Maven in a non-interactive, continuous integration environment. When running in non-interactive mode, Maven will never stop to accept input from the user. Instead, it will use sensible default values when it requires input.

And will also reduce the output messages more or less to the essentials.

聽兲甴掵 2024-07-11 01:37:18

Maven 3.1.x 使用 SLF4j 进行日志记录,您可以在 https:// 找到如何配置它的说明。 maven.apache.org/maven-logging.html

简而言之:修改 ${MAVEN_HOME}/conf/logging/simplelogger.properties,或者通过 设置相同的属性MAVEN_OPTS 环境变量。

例如:将 MAVEN_OPTS 设置为 -Dorg.slf4j.simpleLogger.log.org.apache.maven.cl‌ i.transfer.Slf4jMave‌ nTransferListener=wa‌ rn 配置日志记录批处理模式传输监听器,-Dorg.slf4j.simpleLogger.defaultLogLevel=warn 设置默认日志级别。

Maven 3.1.x uses SLF4j for logging, you can find instructions how to configure it at https://maven.apache.org/maven-logging.html

In short: Either modify ${MAVEN_HOME}/conf/logging/simplelogger.properties, or set the same properties via the MAVEN_OPTS environment variable.

For example: setting MAVEN_OPTS to -Dorg.slf4j.simpleLogger.log.org.apache.maven.cl‌​i.transfer.Slf4jMave‌​nTransferListener=wa‌​rn configures the logging of the batch mode transfer listener, and -Dorg.slf4j.simpleLogger.defaultLogLevel=warn sets the default log level.

蓝颜夕 2024-07-11 01:37:18

官方链接:
https://maven.apache.org/maven-logging.html

您可以添加JVM 参数:

-Dorg.slf4j.simpleLogger.defaultLogLevel=WARN

注意大写。

Official link :
https://maven.apache.org/maven-logging.html

You can add in the JVM parameters :

-Dorg.slf4j.simpleLogger.defaultLogLevel=WARN

Beware of UPPERCASE.

我们只是彼此的过ke 2024-07-11 01:37:18

使用 -q 或 --quiet 命令行选项

Use the -q or --quiet command-line options

弥繁 2024-07-11 01:37:18

如果您只想摆脱 [INFO] 消息,您也可以这样做:

mvn ... | fgrep -v "[INFO]"

要抑制所有输出(错误除外),您可以重定向 stdout/dev/null :(

mvn ... 1>/dev/null

这仅在您使用 bash (或类似的 shell)运行 Maven 命令时有效。)

If you only want to get rid of the [INFO] messages you also could do:

mvn ... | fgrep -v "[INFO]"

To suppress all outputs (except errors) you could redirect stdout to /dev/null with:

mvn ... 1>/dev/null

(This only works if you use bash (or similar shells) to run the Maven commands.)

神仙妹妹 2024-07-11 01:37:18

现有答案可帮助您使用 --quiet 根据日志级别进行过滤。 我发现许多 INFO 消息对于调试很有用,但是下载工件日志消息(如下所示)噪音很大并且没有帮助。

Downloading: http://nexus:8081/nexus/content/groups/public/org/apache/maven/plugins/maven-compiler-plugin/maven-metadata.xml

我找到了这个解决方案:

https ://blogs.itemis.com/en/in-a-nutshell-removing-artifact-messages-from-maven-log-output

mvn clean install -B -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn

The existing answer help you filter based on the log-level using --quiet. I found that many INFO messages are useful for debugging, however the downloading artifact log messages such as the following were noisy and not helpful.

Downloading: http://nexus:8081/nexus/content/groups/public/org/apache/maven/plugins/maven-compiler-plugin/maven-metadata.xml

I found this solution:

https://blogs.itemis.com/en/in-a-nutshell-removing-artifact-messages-from-maven-log-output

mvn clean install -B -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn
杀お生予夺 2024-07-11 01:37:18

我的问题是 -q 太安静了。 我在 CI 下运行 Maven

Maven 3.6.1 (2019 年 4 月)< /a>,您现在有一个在交互模式下下载/上传时抑制传输进度的选项

mvn --no-transfer-progress ....

或者简而言之:

mvn -ntp ... ....

这就是 Ray 提出的在评论中使用 MNG-6605PR 239

My problem is that -q is too quiet. I'm running maven under CI

With Maven 3.6.1 (April 2019), you now have an option to suppress the transfer progress when downloading/uploading in interactive mode.

mvn --no-transfer-progress ....

or in short:

mvn -ntp ... ....

That is what Ray proposed in the comments with MNG-6605 and PR 239.

红颜悴 2024-07-11 01:37:18

我过去曾成功地通过使用此插件配置来静音单个警告,例如 com.example.X

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>properties-maven-plugin</artifactId>
    <version>1.0.0</version>
    <executions>
        <execution>
            <phase>initialize</phase>
            <goals>
                <goal>set-system-properties</goal>
            </goals>
            <configuration>
                <properties>
                    <property>
                        <name>org.slf4j.simpleLogger.log.com.example.X</name>
                        <value>error</value>
                    </property>
                </properties>
            </configuration>
        </execution>
    </executions>
</plugin>

相对于 按照此处建议的方式在外部设置系统属性 是它会自动应用于所有构建/执行。

I've been successful in the past to mute individual warnings e.g. for com.example.X, by using this plugin configuration:

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>properties-maven-plugin</artifactId>
    <version>1.0.0</version>
    <executions>
        <execution>
            <phase>initialize</phase>
            <goals>
                <goal>set-system-properties</goal>
            </goals>
            <configuration>
                <properties>
                    <property>
                        <name>org.slf4j.simpleLogger.log.com.example.X</name>
                        <value>error</value>
                    </property>
                </properties>
            </configuration>
        </execution>
    </executions>
</plugin>

The benefit over setting the system property externally as suggested here is that it automatically applies to all builds / executions.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文