tycho icon indicating copy to clipboard operation
tycho copied to clipboard

`RemapArtifactToMavenRepositoriesMojo` fails when remote repositories are unreachable

Open rbioteau opened this issue 1 year ago • 7 comments

I use this mojo in my build and I need to be able to build in offline mode without internet connection.

This mojo invokes the MirrorApplicationService that look for artifacts in the remote repositories. However, it does not honor the --offline flag and try to reach remote repositories and fail to build when they are not.

I have bypassed the issue by isolating the mojo execution into a dedicated profile that I can disable in my offline build, but I would appreciate a more robust implementation.

Adding the requiresOnline flag to the mojo annotation could be an improvement, as it will skip the execution when the --offline flag is set.

Best regards.

rbioteau avatar Sep 16 '23 12:09 rbioteau

Can you provide an integration-test to demonstrate the issue? Actually Tycho should handle offline globally and I don't even see why RemapArtifactToMavenRepositoriesMojo should require access to the update-site at all...

laeubi avatar Sep 18 '23 08:09 laeubi

@rbioteau what behavior would you expect when being offline? A failure seems the most correct as mojo cannot perform anyway. If you just want to ignore it, then we could image a flag ignoreErrors that you could enable. But overall, the idea of a profile to select whether to require execution or not does seem to be the best one. @laeubi Remap does contact remote Maven repositories for p2 artifacts to check whether they contain an equivalent Maven Artifacts for the given p2 artifact: https://github.com/eclipse-tycho/tycho/blob/fd2527d74966f974f25e80b106912804b92a7d2d/tycho-core/src/main/java/org/eclipse/tycho/p2tools/MirrorApplicationServiceImpl.java#L378

mickaelistria avatar Sep 18 '23 09:09 mickaelistria

In my use case the mojo execution is not mandatory, so being able to skip it (either using the requiresOnline or using a configuration parameter -Dtycho.remapArtifactToMavenRepositories.skip) would be handy. However, there might be use cases where not performing it would lead to errors in the consumer's update-sites I guess.

rbioteau avatar Sep 18 '23 09:09 rbioteau

Feel free to submit a PR to add requiresOnline, as it seems good to add it anyway/

mickaelistria avatar Sep 18 '23 09:09 mickaelistria

Feel free to submit a PR to add requiresOnline, as it seems good to add it anyway/

I think a general <skip> parameter is more suitable / maven like in this case, binding it to online/offline seems strange as indicated above I don't see how this should ever make a difference. We either should use the standard maven-resolver (that already should support online/offline) or skip the online check if one is working offline alltogether. e.g. in offline mode one might simply check the local repository instead...

laeubi avatar Sep 18 '23 09:09 laeubi

What I don't like with the requiresOnline flag is that it will just skip the execution when offline without more information in the build output. As a user, I prefer seeing the mojo fail to analyze the impact of not executing it. Then, having a configuration flag to skip it seems relevant.

Using the standard maven-resolver is relevant, but then you still have to choose what behavior to adopt when offline mode is enabled (fail, warning logs, ignore silently..etc)

in offline mode one might simply check the local repository instead.

What kind of remapping do you apply then ? Do you remap to the artifact local repository path ? It could work to a certain point, but you'll lose the portability of the generated update site.

rbioteau avatar Sep 18 '23 09:09 rbioteau

The online check is only performed to see if the artifact is a "real" maven artifact. "remapping" of artifacts is in general fragile and I won't recommend it, I even don't know any project actually using it and instead one should use real maven-p2 update sites if desired especially if portability is an issue for you.

laeubi avatar Sep 18 '23 09:09 laeubi