johanhaleby / occurrent

Unintrusive Event Sourcing Library for the JVM
https://occurrent.org
124 stars 16 forks source link

Prevent 'examples' and 'test-support' publishing #139

Closed gavvvr closed 1 year ago

gavvvr commented 1 year ago

Hi @johanhaleby This should fix #138

I hope skipNexusStagingDeployMojo will work out (I do not know how to test it for sure) The reason why I used skipNexusStagingDeployMojo for 'test-support' instead of just excluding it like 'examples' is because I think 'test-support' is needed when you publish (because you need to verify/execute tests)

johanhaleby commented 1 year ago

Thanks a lot! If this works it's really great. It's something that can be really useful in other projects as well where I delete test/example projects manually on each release.

johanhaleby commented 1 year ago

But just so I understand it correctly, what does <skipNexusStagingDeployMojo>true</skipNexusStagingDeployMojo> actually do? I want to upload the artifacts to maven central when I make a release. Will this not prevent it?

gavvvr commented 1 year ago

But just so I understand it correctly, what does <skipNexusStagingDeployMojo>true</skipNexusStagingDeployMojo> actually do?

Hi @johanhaleby

Setting skipNexusStagingDeployMojo to true for 'test-support' module prevents the module from being published to remote repository. I found this solution here.

The situation with 'example' module is different. It simply gets ignored when you specify -P release, because whenever you specify a list of desired profiles explicitly (with -P), all profiles which were activeByDefault get deactivated. So, the special examples-module profile which I created to switch on/off 'example' module gets deactivated with explicit -P release.

To sum up, with this PR, when you build or package locally (or on CI) without specifying explicit profiles, example module is included, because it's activeByDefault. When you perform release with -P release and nexus-staging-maven-plugin, neither example nor test-support get published.

The reason why test-support is not handled by custom profile like example is: you need test-support module, when you will build occurrent-project for publishing a release to Maven Central, but at the same time you do not want it to be published. You can't simply turn it off the same way like you can turn off 'example'. So, to prevent 'test-support' from being published, I used skipNexusStagingDeployMojo=true

How it was tested

The above statements were tested by publishing to local Nexus OSS. Here is the quick recipe:

  1. docker run -d -p 8081:8081 --name nexus sonatype/nexus3 to quickly get Nexus OSS up and running
  2. docker exec -it nexus bash -c 'cat /nexus-data/admin.password' to get a temp password for admin user
  3. Go to http://localhost:8081/ and do some mouse clicks to perform initial configuration
  4. Change $distributionManagement.snapshotRepository.url in your pom.xml to be http://localhost:8081/repository/maven-snapshots/, and comment-out gpg plugin
  5. Execute mvn -P release clean deploy. Yes, this command, because OSS version of Nexus does not support staging feature. You will find published components on http://localhost:8081/service/rest/repository/browse/maven-snapshots/org/occurrent/
  6. To conduct more tests, sign in as admin to local Nexus, go to http://localhost:8081/#browse/browse:maven-snapshots:org , select the root folder and delete it with a button
johanhaleby commented 1 year ago

@gavvvr Thank you so much for this PR. It'll not only help Occurrent, but also several of my other open-source libraries. Releasing for example REST Assured, will also be much easier :)