-
-
Notifications
You must be signed in to change notification settings - Fork 421
Add PublishCredentialsModule, MavenPublish and MavenPublishModule #6023
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
|
Hi @lefou, this is my attempt at implementing #5592, building upon @chikei's work in #5601. In the end it does contain quite a few more changes. I hope that's ok, this is what I could come up with. Let me know if this is a non starter or what changes are required to get this merged. Many thanks (also to @chikei)! |
|
Hi @lefou I provided more details in the PR description and fixed a bug. Please have a look! Regarding the open question mentioned in the description I would require some pointers. |
|
Hey @lefou and @lihaoyi, any chance we can move this further along? I know you two are busy and this is all in our free time so I don't want to intrude. It would just be nice to get an indication on timeline. To lobby a little for this feature (not necessarily this PR):
I'd be happy to implement any changes and suggestions or discuss. Many thanks! |
|
Kicked the failing tests to check if they're just flaky, if so we can merge this |
|
@maxstreese I think maybe the last thing necessary is to update the |
|
CC @lefou in case you have any feedback before I merge this |
| import mill.api.* | ||
| import mill.javalib.PublishModule.PublishData | ||
| import mill.util.Tasks | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you add some scaladoc to this trait and its companion object, and explain what is the difference between this and the normal trait PublishModule and object SonatypeCentralPublishModule we typically tell people to use?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Also, do we need this
traitat all? Ideally we should just have everyone extendPublishModuleand use different companion object external modules to publish them to different places
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Regarding "do we need this trait at all": I was just exactly following what is already done in trait SonatypeCentralPublishModule and its companion object. Therefore it seems clean to me to not break with that design?
Regarding what the difference is: What SonatypeCentralPublishModule does for Sonatype Central, MavenPublishModule does for "plain" Maven. I can certainly make this distinction clear by providing a scaladoc for both modules.
To try to explain my understanding as best as possible: SonatypeCentralPublishModule is specifically for publishing to the service https://central.sonatype.com/. Because of at least staging releases (not sure if something else), this is not exactly the same as publishing to a repository that "just" follows the Maven2 Repository Layout (even if that repo is managed by the Sonatype software). That is the reason why MavenPublishModule has been brought to life. Now to go even deeper into this, I believe it should be possible and in fact probably also cleaner and closer to reality, to have all of this functionality in one module and/or publish task, which can be configured in a multitude of ways (e.g. publish to central or private; specify credentials or not; cryptographically sign or not). This is what was actually done in the deprecated publishAll task of the PublishModule itself and is stated in the Mill docs (though - if I remember my testing correctly - was not 100 % compliant for "plain" Maven publishing because it did not create maven-metadata.xml). Implementing this unified approach is something that I consider both out-of-scope for this PR and a bit out of my comfort zone. Though I'd certainly be open to try if you agree :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the important thing is to make sure ./mill mill.javalib.MavenPublishModule/ works for publishing normal mill.javalib.publish.PublishModules, and not just this particular trait. The same way that ./mill mill.javalib.SonatypeCentralPublishModule/ works on normal mill.javalib.publish.PublishModules without requiring the individual modules extend mill.javalib.SonatypeCentralPublishModule
If that works, then we can probably do without this trait and just ask people to use the companion object
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In my understanding ./mill mill.javalib.MavenPublishModule/ works for publishing normal mill.javalib.publish.PublishModules with the current implementation in this PR, because MavenPublishModule is an ExternalModule, it's default task is publishAll and publishAlls publishArtifacts parameter by default resolves to __:PublishModule.publishArtifacts (following exactly what is done in SonatypeCentralPublishModule). Or am I missing something here?
I would propose to still keep the MavenPublishModule trait for two reasons:
- This follows the design of
SonatypeCentralPublishModuleand therefore is uniform - It gives users the option to either run
./mill mill.javalib.MavenPublishModule/or (for example)./mill __.publishMaven. I think giving users the second option is important, because of the following scenario: What if I want to publish some of my modules to Sonatype Central and some to a private repo? Or what if I want to publish to different private repos? When keeping theMavenPublishModuletrait, this is easy to express in the build by extending it in different modules and supplying different parameters. I think with the external module alone this would be more tricky?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just to clarify, the external module's command accepting a --publish-artifacts option itself accepting a task query like __.publishArtifacts or <my-module>.publishArtifacts should already allow to publish selected modules via different methods.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah I was missing this part, thanks! So what I could do to put this in - say - a shared module in a build is something like the below right?
package millbuild
import mill.*
import mill.api.Task.Simple
import mill.javalib.MavenPublishModule
import mill.scalalib.*
import mill.scalalib.publish.*
import mill.util.Tasks
trait FooModule extends ScalaModule, PublishModule:
def publishMaven = MavenPublishModule.publishAll(
publishArtifacts = Tasks(Seq(publishArtifacts)),
username = "",
password = "",
bundleName = "",
releaseUri = "",
snapshotUri = "",
)
def publishVersion = "0.1.0"
def pomSettings = PomSettings(
description = "",
organization = "",
url = "",
licenses = Seq.empty,
versionControl = VersionControl.github("", ""),
developers = Seq.empty,
)In this case should I provide this option in the docs? And related: Is there a different way than using the Tasks util for this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think expecting people to pass the values via the CLI or env variables would be fine for now, that's what we mostly recommend for SonatypePublishModule and it seems to work
| import mill.javalib.PublishModule.PublishData | ||
| import mill.util.Tasks | ||
|
|
||
| trait MavenPublishModule extends PublishModule, MavenWorkerSupport, SonatypeCredentialsModule, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If SonatypeCredentialsModule is being used for non-sonatype publishing as well, we should mention that in its scaladoc
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I actually had not considered this inconsistency. If we continue with my current implementation, we would actually expect the user to provide the environment variables MILL_SONATYPE_USERNAME and MILL_SONATYPE_PASSWORD for publishing to "plain" Maven as well. I guess I was subconsciously thinking "it will also be Sonatype". I am not sure what the right path forward is here. Should we keep it as is and just add the scaladoc? Or should we maybe rename this module and make the environment variable different for Sonatype and "plain" Maven?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think maybe let's rename the environment variable to plain MAVEN_PUBLISH_USERNAME and MAVEN_PUBLISH_PASSWORD for people using MavenPublishModule?
2f01ebd to
9de0f54
Compare
|
I have addressed your code reviews, please have another look! Things that have been changed
Dependency bug found during testing I believe I have also found a bug related to using the Take the below dummy //| mill-version: 1.0.6
//| mill-jvm-version: temurin:21
package build
import mill.*
import mill.scalalib.*
import mill.scalalib.publish.*
import mill.util.Tasks
import mill.javalib.SonatypeCentralPublishModule
object `package` extends ScalaModule, PublishModule:
def scalaVersion = "3.7.4"
def publishVersion = "0.1.0"
def pomSettings = PomSettings(
description = "",
organization = "",
url = "",
licenses = Seq.empty,
versionControl = VersionControl.github("", ""),
developers = Seq.empty,
)
def publishSonatypeCentral = SonatypeCentralPublishModule.publishAll(
publishArtifacts = Tasks(Seq(publishArtifacts)),
)What I get is: I am pretty sure this is due to these lines here (and in the scalalib module respectively). Should I create a separate PR for that or change the dependency to be part of the |
Summary
Implements #5592 and builds upon #5601.
High Level Overview of Changes
This PR implements three traits:
MavenPublishModuleis meant to mirrorSonatypeCentralPublishModulefor plain (!?) Maven repositoriesMavenModulecontains the actual publishing logic. This has been taken from parts ofSonatypeCentralPublishModuleand is now extended by bothMavenPublishModuleas well assSonatypeCentralPublishModuleto share codeMavenCredentialsModulecontains tasks for obtaining Maven/Sonatype credentials. These tasks have been extracted from theSonatypeCentralPublishModuleto be shared by both it and the newMavenPublishModuleDifferences between this PR and #5601
Code Structure
#5601 essentially copied parts of
SonatypeCentralPublishModuleto createMavenPublishModule. Apart from duplicating code, this also created code you may find confusing in places (e.g. by containing a function named publishSnapshot which is used to publish both release and snapshot artifacts). This PR tries to improve upon that by instead factoring out all code which can be factored out.Removal of Unused Settings
#5601 defines the tasks
mavenConnectTimeout,mavenReadTimeoutandmavenAwaitTimeoutas part of theMavenPublishModule. These are however not actually used anywhere. They are used inSonatypeCentralPublishModuleand are specific to publishing releases to Sonatype Central.Bugfix for Choosing the Repo URI
The below was changed after being identified during testing with a private build.
Open Question: Build Compilation Error When Extending
MavenPublishModuleWhen running
./mill dist.installLocalCacheand then using the localSNAPSHOTversion of mill including the changes made in this PR in a build and extendingMavenPublishModulein a local build module, I currently get the following exception when running./mill resolve _on that build:This error can be removed by defining
Deps.sonatypeCentralClientas amvnDepsinstead of both acompileMvnDepsand arunMvnDepsinlibs/scalalib/package.millandlibs/javalib/package.mill. I do not know why this is the case and would require some help here.