-
Notifications
You must be signed in to change notification settings - Fork 410
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
Refactor Maven Runner build config #2911
Refactor Maven Runner build config #2911
Conversation
import java.io.File | ||
|
||
@Suppress("LeakingThis") | ||
open class SetupMaven : Sync() { |
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.
The properties in this file were moved to an extension in the new maven-cli-setup.gradle.kts
convention plugin
} | ||
|
||
init { | ||
from(mavenBinaryConfiguration.map { file -> project.zipTree(file) }) |
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.
This line caused eager configuration, so the binary was always downloaded whether it was necessary or not.
val setupMavenTask = project(":runners:maven-plugin").tasks.withType<SetupMaven>().single() | ||
dependsOn(setupMavenTask) |
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.
Instead of using a cross-project dependency to re-use the Maven exec, just download it again.
Gradle will cache the downloaded dependency, so it's fine to set it up twice in different subprojects.
} | ||
|
||
into(temporaryDir) |
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.
Instead of worrying about Sync/Copy tasks overwriting, and having to use preserve {}
, I think it's best to always use Sync into the task's temporary dir, and use a final Sync task (prepareMavenPluginBuildDir
) to sync the files from the other Sync tasks in one go.
doLast("normalize maven-plugin-help.properties") { | ||
// The maven-plugin-help.properties file contains a timestamp by default. | ||
// It should be removed as it is not reproducible and impacts Gradle caching | ||
val pluginHelpProperties = workingDir.resolve("maven-plugin-help.properties") | ||
pluginHelpProperties.writeText( | ||
buildString { | ||
val lines = pluginHelpProperties.readText().lines().iterator() | ||
// the first line is a descriptive comment | ||
appendReproducibleNewLine(lines.next()) | ||
// the second line is the timestamp, which should be ignored | ||
lines.next() | ||
// the remaining lines are properties | ||
lines.forEach { appendReproducibleNewLine(it) } | ||
} | ||
) | ||
} |
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.
Unfortunately the generated maven-plugin-help.properties
contains a timestamp, so Gradle will always consider the output out-of-date.
I wrote this code to fix it - but maybe there's a Maven flag that will disable the timestamp?
This is perhaps a bit OTT/pre-optimising.
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 don't understand what helpMojo is supposed to achieve, and I can't google anything sensible. It looks like it should either generate the help
goal (which Dokka's Maven plugin doesn't have) or maybe add some help documentation? Were you able to figure it out?
Nothing looks broken to me, so I think it's fine to ignore the timestamp. Perhaps, at some point our Maven plugin should be revisited as well 😅
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 it auto generates a 'help' command based on the properties in the Maven plugin
The file it generates is in runners/maven-plugin/build/maven/generated-sources
But, like you, I'm not sure! I've never developed a Maven plugin.
package org.jetbrains.dokka.maven;
/**
* Display help information on dokka-maven-plugin.<br>
* Call <code>mvn dokka:help -Ddetail=true -Dgoal=<goal-name></code> to display parameter details.
* @author maven-plugin-tools
* @goal help
* @requiresProject false
* @threadSafe
*/
public class HelpMojo
extends AbstractMojo
{
/**
* If <code>true</code>, display all settable properties for each goal.
*
* @parameter property="detail" default-value="false"
*/
private boolean detail;
/**
* The name of the goal for which to show help. If unspecified, all goals will be displayed.
*
* @parameter property="goal"
*/
private java.lang.String goal;
/**
* The maximum length of a display line, should be positive.
*
* @parameter property="lineLength" default-value="80"
*/
private int lineLength;
...
I was looking at other options, and I found this Gradle plugin: https://github.com/britter/maven-plugin-development. It might help with developing a Maven plugin, but on the other hand, the current approach seems to be working.
expand( | ||
"mavenVersion" to setupMavenProperties.mavenVersion, | ||
"dokka_version" to dokka_version, | ||
"mavenPluginToolsVersion" to setupMavenProperties.mavenPluginToolsVersion, | ||
) |
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.
using the Gradle expand ()
is a little nicer to use and look at than the previous manual find and replace.
To achieve this, I needed to update the properties in pom.tpl.xml
to be of the format ${mavenVersion}
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.
Looks very neat, and thank you for the explanation comments! Only have optional nitpicks
I'll start the integration tests and, if everything's good, will merge it
doLast("normalize maven-plugin-help.properties") { | ||
// The maven-plugin-help.properties file contains a timestamp by default. | ||
// It should be removed as it is not reproducible and impacts Gradle caching | ||
val pluginHelpProperties = workingDir.resolve("maven-plugin-help.properties") | ||
pluginHelpProperties.writeText( | ||
buildString { | ||
val lines = pluginHelpProperties.readText().lines().iterator() | ||
// the first line is a descriptive comment | ||
appendReproducibleNewLine(lines.next()) | ||
// the second line is the timestamp, which should be ignored | ||
lines.next() | ||
// the remaining lines are properties | ||
lines.forEach { appendReproducibleNewLine(it) } | ||
} | ||
) | ||
} |
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 don't understand what helpMojo is supposed to achieve, and I can't google anything sensible. It looks like it should either generate the help
goal (which Dokka's Maven plugin doesn't have) or maybe add some help documentation? Were you able to figure it out?
Nothing looks broken to me, so I think it's fine to ignore the timestamp. Perhaps, at some point our Maven plugin should be revisited as well 😅
val mavenVersion = "3.5.0" | ||
val mavenPluginToolsVersion = "3.5.2" |
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.
Very much optional, while we're at it: I think we actually forget to check/update the Maven version because it's buried in a place we don't visit that much. Extracting it to gradle.properties
(or into the toml
in the other PR) would not hurt
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.
Good point, I think so too. For now I'll put it in gradle.properties
, and I think that later they can be moved to libs.versions.toml
as part of #2884
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.
It was a little more work than I thought to refactor this, but I think it was worth it.
It revealed that the CrossPlatformExec
task wasn't really needed, and could be replaced with a Provider that would determine the current operating system and use mvn.cmd
on Windows, else use mvn
.
Hopefully the GitHub Workflow tests pass 🤞
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.
Oof, sorry for asking you to do that then, and thanks for doing! I do think it was worth it though!
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.
no apology needed :)
120cb21
to
baefed3
Compare
…sPlatformExec (replaced with a OS provider that maps Windows to `mvn.bat` otherwise to `mvn`)
After I'll start integration tests once again, will merge it once they pass 👍 👍 |
Not at all! Good job noticing it, and thanks for fixing it. |
Part of #2703
Updates the Maven runner build logic to work better with the Gradle API