session.getCurrentProject() returns 空 - Maven 扩展
session.getCurrentProject() returns null - Maven extensions
我正在尝试编写一个 Maven 扩展来计算每个构建会话的持续时间。这是我的分机:
@Parameter( defaultValue = "${project}", readonly = true, required = true )
private MavenProject project;
@Component(role = AbstractMavenLifecycleParticipant.class)
public class BuildTimeLogger extends AbstractMavenLifecycleParticipant {
public void afterSessionStart(MavenSession session) throws MavenExecutionException {
System.out.println("${project}: "+project);
System.out.println("Top level project:"+session.getTopLevelProject());
System.out.println("session.getcurrentproject():"+session.getCurrentProject()); }
}
我不确定为什么上面所有的打印语句都会打印 null
。我是否正确使用会话对象?我的理解是 Maven 应该发送正在构建的项目的所有会话详细信息。我在不同的项目上尝试过这个,但似乎对我不起作用。
我又试了一下这个,发现它确实在从 afterProjectsRead()
打印时打印了这些细节。
从官方文档粘贴:
afterSessionStart - Invoked after MavenSession instance has been
created. This callback is intended to allow extensions to inject
execution properties, activate profiles and perform similar tasks that
affect MavenProject instance construction.
afterProjectsRead - Invoked after all MavenProject instances have been
created. This callback is intended to allow extensions to manipulate
MavenProjects before they are sorted and actual build execution
starts.
所以我认为 MavenProject 实例尚未在 afterSessionStart() 中创建。
认为它绝对可以更具描述性:-/
我正在尝试编写一个 Maven 扩展来计算每个构建会话的持续时间。这是我的分机:
@Parameter( defaultValue = "${project}", readonly = true, required = true )
private MavenProject project;
@Component(role = AbstractMavenLifecycleParticipant.class)
public class BuildTimeLogger extends AbstractMavenLifecycleParticipant {
public void afterSessionStart(MavenSession session) throws MavenExecutionException {
System.out.println("${project}: "+project);
System.out.println("Top level project:"+session.getTopLevelProject());
System.out.println("session.getcurrentproject():"+session.getCurrentProject()); }
}
我不确定为什么上面所有的打印语句都会打印 null
。我是否正确使用会话对象?我的理解是 Maven 应该发送正在构建的项目的所有会话详细信息。我在不同的项目上尝试过这个,但似乎对我不起作用。
我又试了一下这个,发现它确实在从 afterProjectsRead()
打印时打印了这些细节。
从官方文档粘贴:
afterSessionStart - Invoked after MavenSession instance has been created. This callback is intended to allow extensions to inject execution properties, activate profiles and perform similar tasks that affect MavenProject instance construction.
afterProjectsRead - Invoked after all MavenProject instances have been created. This callback is intended to allow extensions to manipulate MavenProjects before they are sorted and actual build execution starts.
所以我认为 MavenProject 实例尚未在 afterSessionStart() 中创建。 认为它绝对可以更具描述性:-/