apache / apache/maven

[MNG-7510] Enhance AbstractMavenLifecycleParticipant to watch for buildProject events

Open
#9,285 0 comments 0 reactions 0 assignees View on GitHub
enhancement priority:major
Dominant language
Java
Stars
5.3k
Forks
3.1k
Avg merge
20h 42m
Merged PRs (30d)
297

Description

**[Christoph Läubrich](https://issues.apache.org/jira/secure/ViewProfile.jspa?name=laeubi)** opened **[MNG-7510](https://issues.apache.org/jira/browse/MNG-7510?redirect=false)** and commented

Currently Tycho injects some dependencies into the maven model at a very early state. As this computation is time consuming, it has several drawbacks:

 
1. Even if one executes some goals that do not require the resolving of these artifacts, the computation is performed
2. If computation fails for one module the whole build fails, so flags like -fae are not really usable and implementing such support directly is very complex
3. If running a parallel build, the build can't start unless we have computed all modules

For this I have now prototype a new approach that only computes the absolute necessary parts and delays the heavy computation into a mojo called in the initialization phase of the life-cycle. This works quite well but currently requires some hacks:
1. I need to force maven to throw away all resolved state because otherwise later injected dependencies are missing, I'm currently use  project.setDependencyArtifacts(null); for this but of course it feels like waste of throw away all the data and rely on internal behavior of maven
2. other maven tools are not aware of this (e.g. dependency:list) and if I execute such one, the user needs to add an explicitly manual mojo execution

Because of this, I like to discuss/suggest a way for a project scoped extension to participate in the collection of DependencyArtifacts.

For now, I found two possible "vectors":
1. DefaultProjectArtifactFactory currently converts Artifact out of the Dependency and it seems one might want to hook in here to provide additional Artifact/Dependency, but it seems to be to narrow to be useful in general.
2. LifecycleDependencyResolver.resolveProjectDependencies(MavenProject, Collection\, Collection\, MavenSession, boolean, Set\)  seems the most suitable place as it actually do the computation and checks.
3. LifecycleModuleBuilder#buildProject is actually the most valuable / generic place I think as it would also allow other use-cases where one want to get notified about a project build started, and as AbstractMavenLifecycleParticipant is abstract an extension here would even be backward-compatible and wont require any new interfaces/services/... to be created.

 

I'm in favor of option (3) but still wanted to still explain how I got there of course and feedback/ideas are appreciated! I'll try to provide a PR for (3) as well so one could maybe better discuss on the actual code changes.

 

Beside that there is also org.apache.maven.execution.ProjectExecutionListener that seem to serve similar purpose, but it javadoc says:

This interface is part of work in progress and can be changed or removed without notice.

 

---
No further details from [MNG-7510](https://issues.apache.org/jira/browse/MNG-7510?redirect=false)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.