1 |
Hi Kaibo, |
2 |
|
3 |
I'd like to suggest an alternative to using a local Maven repository for |
4 |
making Portage-built artifacts available to Maven builds. |
5 |
|
6 |
Maven also makes it possible to use a "Maven extension" for providing |
7 |
artifacts that do not come from a remote Maven repository. If a Maven |
8 |
extension provides an implementation of a "WorkspaceReader", Maven will |
9 |
query that implementation for artifacts before checking any repository |
10 |
for the artifacts. (An example of such an extension is used by |
11 |
M2Eclipse, the Maven integration for the Eclipse IDE, which provides |
12 |
artifacts built from Java projects within Eclipse.) |
13 |
|
14 |
Using such a Maven extension would provide greater flexibility than a |
15 |
local Maven repository, because ebuilds could modify artifact resolution |
16 |
for their Maven builds by configuring the extension. (I believe that |
17 |
this would be trickier when using a local Maven repository, in |
18 |
particular with multiple ebuilds running in parallel.) |
19 |
|
20 |
I don't know what a similar mechanism in Gradle would be, but I'd guess |
21 |
that Gradle provides similar extension points. |
22 |
|
23 |
When thinking about Java builds within portage some weeks ago, I |
24 |
actually wrote a very simple such extension, to see if this approach |
25 |
actually works (see |
26 |
https://github.com/hsudbrock/portage-maven-workspace-reader), and it did |
27 |
work fine. (This extension resolves artifacts that were "registered" by |
28 |
other ebuilds by putting a file in a specific directory, where the file |
29 |
contains the location of the artifact on the hard disk - but this is |
30 |
just a very simple "proof of concept".) |
31 |
|
32 |
What do you think about this alternative idea? |
33 |
|
34 |
Best wishes, |
35 |
Henning |
36 |
|
37 |
On 15.03.21 14:02, Kaibo Ma wrote: |
38 |
> Hi all, |
39 |
> This is an RFC copied from a bug (https://bugs.gentoo.org/776007 |
40 |
> <https://bugs.gentoo.org/776007>), and I have added a new section |
41 |
> because I realized maven local would not be a good destination for |
42 |
> system-wide packages. |
43 |
> |
44 |
> ----- |
45 |
> |
46 |
> 0. Motivation |
47 |
> |
48 |
> Java packaging has become more difficult on Gentoo because maven/Gradle, |
49 |
> the two main build systems for java, is unsupported. When java packages |
50 |
> migrated from their ant builds to maven/Gradle, most of the packages |
51 |
> have not been updated since. I know that in Java overlay, the packaging |
52 |
> practices in general is to patch the pom.xml files to work with local |
53 |
> jars, but it does not work with Gradle and can be difficult when working |
54 |
> with large projects. |
55 |
> |
56 |
> 1. Challenges |
57 |
> |
58 |
> - maven modules/artifacts do not work well with java-config. They |
59 |
> generally have a group, which resolves name collisions, but java-config |
60 |
> currently does not have a group variable. |
61 |
> |
62 |
> - it will be hard to reinvent the wheel. If the solution was to |
63 |
> rewrite pom.xml/build.gradle files, it would have to resolve the |
64 |
> dependencies correctly with all the version constraints instead of |
65 |
> relying on the build system. Currently, for java-config packages can |
66 |
> only depend on a specific slot of a library, but some might work with |
67 |
> newer versions of their dependencies. |
68 |
> |
69 |
> - plugins are also hard to create in Gradle. Custom resolution of |
70 |
> dependencies or specifying a custom repository is not easy because it |
71 |
> involves "internal" API without much documentation. Fedora's XMvn |
72 |
> project can be used as a starting point but at the time of writing, XMvn |
73 |
> is outdated and missing some implementations for newly added interface |
74 |
> methods in Gradle's API. |
75 |
> |
76 |
> 2. Proposed idea |
77 |
> |
78 |
> Maven/Gradle both have an offline mode which restricts them from |
79 |
> fetching online files. For java libraries, they will be published to the |
80 |
> local maven repository, which makes it available for other java programs |
81 |
> using maven/gradle that depends on the library. |
82 |
> |
83 |
> Packages that still use java-pkg-simple.eclass can be kept because they |
84 |
> are generally not available in maven, so it is rare for other packages |
85 |
> to depend on them. The eclass and java-config should be updated for some |
86 |
> packages that depend on other packages that get published to mavenLocal, |
87 |
> but this seems like a rare case. Those packages can also just get |
88 |
> converted to a maven/project using patches. |
89 |
> |
90 |
> For applications, the launcher scripts should also be changed to parse |
91 |
> local artifacts with POM files. |
92 |
> If this were to be implemented, newer (revisions/subslots? Or old slots |
93 |
> with -new at the end?) packages would be incompatible with older |
94 |
> versions of packages. |
95 |
> |
96 |
> 3. ERRATA |
97 |
> |
98 |
> The local maven repository would not be a good fit since it is on a |
99 |
> per-user basis (~/.m2). The correct way would be to define a path for |
100 |
> installing (such as /usr/share/.m2), and pass that to build tools as a |
101 |
> URL (file:///usr/share/.m2). |
102 |
> |
103 |
> Feel free to reply if you have any questions or improvements. |
104 |
> Kaibo Ma |