I'm seeing a strange problem with the publishToMav...
# community-support
s
I'm seeing a strange problem with the publishToMavenLocal task that I cannot explain and cannot discover the reason for. First, publishing remotely works fine. I also created a separate publishing repository which is a local directory - publishing there also works fine. But as I said there is some wonkiness in publishing to maven-local. The build has subprojects which should get published. However, publishing to maven-local only publishes some of them. The subprojects which get published are random - sometimes one gets published sometimes it does not. Even "worse", if I run the task again more get published. I have to run the task multiple times to get them all published. Here is some info output for publishing for one of the subprojects -
Copy code
[hibernate-orm]$ gradlew publishToMavenLocal --console=plain --info
...
Resolve mutations for :hibernate-scan-jandex:publishPublishedArtifactsPublicationToMavenLocal (Thread[Execution worker Thread 3,5,main]) started.
:hibernate-scan-jandex:publishPublishedArtifactsPublicationToMavenLocal (Thread[Execution worker Thread 3,5,main]) started.
...
> Task :hibernate-scan-jandex:publishPublishedArtifactsPublicationToMavenLocal
Custom actions are attached to task ':hibernate-scan-jandex:publishPublishedArtifactsPublicationToMavenLocal'.
Caching disabled for task ':hibernate-scan-jandex:publishPublishedArtifactsPublicationToMavenLocal' because:
  Not worth caching
Task ':hibernate-scan-jandex:publishPublishedArtifactsPublicationToMavenLocal' is not up-to-date because:
  Task has not declared any outputs despite executing actions.
PublishToMavenLocal (publishedArtifacts)
    - org.hibernate.orm : hibernate-scan-jandex : jar 
    - artifacts (3)...
        - artifact (javadoc) : /home/sebersole/projects/hibernate-orm/6.0/hibernate-orm/hibernate-scan-jandex/target/libs/hibernate-scan-jandex-7.0.0-SNAPSHOT-javadoc.jar (152650)
        - artifact (null) : /home/sebersole/projects/hibernate-orm/6.0/hibernate-orm/hibernate-scan-jandex/target/libs/hibernate-scan-jandex-7.0.0-SNAPSHOT.jar (16865)
        - artifact (sources) : /home/sebersole/projects/hibernate-orm/6.0/hibernate-orm/hibernate-scan-jandex/target/libs/hibernate-scan-jandex-7.0.0-SNAPSHOT-sources.jar (11563)
Publishing to maven local repository
After this run,
hibernate-scan-jandex
does not show up in my maven-local. As I said, it is random which subprojects get published each time. Any ideas where to look?
v
Only thing that comes to mind is, if multiple projects publish to the same coordinates and one overwrites the other, or that something else is deleting the files after publishing. Maybe use some tool that monitors disk activity in that directory to see whether the files get put there and then deleted or whether they really do not get added in the first place. Optimally, such tool could also tell you which process created and / or deleted the files. On Windows I'd use
ProcessMonitor
for that, not sure whether a similar tool exists for *nix, but I'd guess so. Other than that I guess you would need to debug the code that does the publishing and see what happens. That could also be used for the former investigation by setting a breakpoint right after the files were copied, check that the files are there, then continue running and check whether the files were deleted again, but that would probably only work properly if it is something inside the Gradle JVM that deletes the files again if that is the problem.
s
Sorry, I should have mentioned that. I am using
inotifywait
. The directory for the non-published subprojects is never touched by the Gradle process
It literally never writes the artifacts
I guess I'll have to debug 😞
v
Sounds like it, yeah. Never heard of
pTML
not working so far.
s
There are a few SO posts
But none seem to match exactly
v
How reproducible is the failure? I'd be willing to test your project here whether it also happens or not if it is somewhat reproducible and not only a one percent failurechance.
s
So this is interesting maybe. Or at least surprising to me... I stepped into
AbstractMavenPublisher#publish
and see that its
SnapshotMetadataResult snapshotMetadataResult
seems to refer to a different subproject. Oddly all the previous "check"/"validate" stuff used the correct details
Its very reproducible. Multiple members of the team see it - in fact everyone who tries
The randomness is simply which modules get published during each run
So this is wrong I assume... I am limiting breakpoints to one particular subproject named
hibernate-scan-jandex
. In the method I mentioned above it resolves
SnapshotMetadataResult
pointing to
file:/home/sebersole/projects/hibernate-orm/6.0/hibernate-orm/tooling/hibernate-maven-plugin/target/maven-embedder/maven-local/org/hibernate/orm/hibernate-scan-jandex/7.0.0-SNAPSHOT/maven-metadata-local.xml
hibernate-maven-plugin
is a completely separate subproject. Ultimately it is using a "correct" file, but the directory path seems odd
To reproduce you can simply check out https://github.com/hibernate/hibernate-orm (main) and run pTML
Ok, I see why. Not yet the reason, but I see what is going on
It does in fact have something to do with that incorrect path I mentioned. Some of the modules get published there and some get published to the real maven-local
Odd that its random
Ok, found it 🙂
Fundamentally the problem is trying to develop a Maven plugin inside a Gradle build
v
👌
Recently a plugin to make this easier was release by gradlex iirc
Maybe that is something that can help you
s
Yep, looking at that right now 🙂
My attempt was clearly subpar 😉
See none of them support running tests afaict unfortunately
Which is actually where my attempt gets into trouble
So here is what I think is the problem. Does this sound reasonable/likely? I wrote a maven-embedder plugin. Maven Embeder is the name of the "maven tooling". I need to set the maven-local path for the embedder to something different in order to run tests. This all happens as a Gradle build service. I had thought that changing the maven-local path there would be safe as I had assumed Gradle had already looked that up and cached it. But apparently not. Based on this, I think I'm going to have to instead use Maven Embedder via the worker api
v
Not sure how / why you use a build service there. But a build service is scoped to the whole build execution right now. If you need a separate one per project, you would have to register the build service multiple times with different names, for example
"myBuildService | ${project.path}"
.
s
Not sure how / why you use a build service there
You mean as opposed to directly using MavenCLI in tasks?
Anyway, I think initially what we will do is a cheap hack - simply use the normal maven-local path and simply delete the flles we write there after
This all has to do with how you test Maven plugins
v
Sounds like a feature request to the mentioned plugin 😄
s
👌 1