diff options
author | Adam <897017+aSemy@users.noreply.github.com> | 2023-10-12 11:40:43 +1300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-10-12 00:40:43 +0200 |
commit | 514cbb11962ba77abf5b35f7698b84f1aef1e813 (patch) | |
tree | a0e5f5c0320e1df579210cadd316ed8db2fee089 /runners | |
parent | 33210a46c7f92f868af98efa04c31295c7a224bf (diff) | |
download | dokka-514cbb11962ba77abf5b35f7698b84f1aef1e813.tar.gz dokka-514cbb11962ba77abf5b35f7698b84f1aef1e813.tar.bz2 dokka-514cbb11962ba77abf5b35f7698b84f1aef1e813.zip |
Fix Maven plugin help task (#3036)
Fixes #3035
Diffstat (limited to 'runners')
-rw-r--r-- | runners/maven-plugin/api/maven-plugin.api | 5 | ||||
-rw-r--r-- | runners/maven-plugin/build.gradle.kts | 93 | ||||
-rw-r--r-- | runners/maven-plugin/pom.template.xml | 26 |
3 files changed, 85 insertions, 39 deletions
diff --git a/runners/maven-plugin/api/maven-plugin.api b/runners/maven-plugin/api/maven-plugin.api index 28d96bd3..069e7744 100644 --- a/runners/maven-plugin/api/maven-plugin.api +++ b/runners/maven-plugin/api/maven-plugin.api @@ -94,6 +94,11 @@ public final class org/jetbrains/dokka/maven/ExternalDocumentationLinkBuilder { public final fun setUrl (Ljava/net/URL;)V } +public class org/jetbrains/dokka/maven/HelpMojo : org/apache/maven/plugin/AbstractMojo { + public fun <init> ()V + public fun execute ()V +} + public final class org/jetbrains/dokka/maven/MavenDokkaLogger : org/jetbrains/dokka/utilities/DokkaLogger { public fun <init> (Lorg/apache/maven/plugin/logging/Log;)V public fun debug (Ljava/lang/String;)V diff --git a/runners/maven-plugin/build.gradle.kts b/runners/maven-plugin/build.gradle.kts index 5e279298..825493ad 100644 --- a/runners/maven-plugin/build.gradle.kts +++ b/runners/maven-plugin/build.gradle.kts @@ -2,7 +2,6 @@ * Copyright 2014-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. */ -import org.gradle.kotlin.dsl.support.appendReproducibleNewLine import org.jetbrains.registerDokkaArtifactPublication plugins { @@ -47,77 +46,93 @@ val generatePom by tasks.registering(Sync::class) { into(temporaryDir) } -val prepareMavenPluginBuildDir by tasks.registering(Sync::class) { - description = "Prepares all files for Maven Plugin task execution" +val prepareHelpMojoDir by tasks.registering(Sync::class) { + description = "Prepare files for generating the Maven Plugin HelpMojo" group = mavenPluginTaskGroup - from(tasks.compileKotlin.flatMap { it.destinationDirectory }) { into("classes/java/main") } - from(tasks.compileJava.flatMap { it.destinationDirectory }) { into("classes/java/main") } - + into(layout.buildDirectory.dir("maven-help-mojo")) from(generatePom) - - into(mavenCliSetup.mavenBuildDir) } val helpMojo by tasks.registering(Exec::class) { + description = "Generate the Maven Plugin HelpMojo" group = mavenPluginTaskGroup - dependsOn(tasks.installMavenBinary, prepareMavenPluginBuildDir) + dependsOn(tasks.installMavenBinary, prepareHelpMojoDir) - workingDir(mavenCliSetup.mavenBuildDir) + workingDir(prepareHelpMojoDir.map { it.destinationDir }) executable(mavenCliSetup.mvn.get()) args("-e", "-B", "org.apache.maven.plugins:maven-plugin-plugin:helpmojo") - outputs.dir(mavenCliSetup.mavenBuildDir) - - 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) } - } - ) + outputs.dir(workingDir) +} + +val helpMojoSources by tasks.registering(Sync::class) { + description = "Sync the HelpMojo source files into a SourceSet SrcDir" + group = mavenPluginTaskGroup + from(helpMojo) { + eachFile { + // drop 2 leading directories + relativePath = RelativePath(true, *relativePath.segments.drop(2).toTypedArray()) + } } + includeEmptyDirs = false + into(temporaryDir) + include("**/*.java") +} + +val helpMojoResources by tasks.registering(Sync::class) { + description = "Sync the HelpMojo resource files into a SourceSet SrcDir" + group = mavenPluginTaskGroup + from(helpMojo) + into(temporaryDir) + include("**/**") + exclude("**/*.java") +} + +sourceSets.main { + // use the generated HelpMojo as compilation input, so Gradle will automatically generate the mojo + java.srcDirs(helpMojoSources) + resources.srcDirs(helpMojoResources) +} + +val preparePluginDescriptorDir by tasks.registering(Sync::class) { + description = "Prepare files for generating the Maven Plugin descriptor" + group = mavenPluginTaskGroup + + into(layout.buildDirectory.dir("maven-plugin-descriptor")) + + from(tasks.compileKotlin) { into("classes/java/main") } + from(tasks.compileJava) { into("classes/java/main") } + from(helpMojoResources) } val pluginDescriptor by tasks.registering(Exec::class) { + description = "Generate the Maven Plugin descriptor" group = mavenPluginTaskGroup - dependsOn(tasks.installMavenBinary, prepareMavenPluginBuildDir) + dependsOn(tasks.installMavenBinary, preparePluginDescriptorDir) - workingDir(mavenCliSetup.mavenBuildDir) + workingDir(preparePluginDescriptorDir.map { it.destinationDir }) executable(mavenCliSetup.mvn.get()) - args( - "-e", - "-B", - "org.apache.maven.plugins:maven-plugin-plugin:descriptor" - ) + args("-e", "-B", "org.apache.maven.plugins:maven-plugin-plugin:descriptor") - outputs.dir(layout.buildDirectory.dir("maven/classes/java/main/META-INF/maven")) + outputs.dir("$workingDir/classes/java/main/META-INF/maven") } tasks.jar { - dependsOn(pluginDescriptor, helpMojo) metaInf { - from(mavenCliSetup.mavenBuildDir.map { it.dir("classes/java/main/META-INF") }) + from(pluginDescriptor) { + into("maven") + } } manifest { attributes("Class-Path" to configurations.runtimeClasspath.map { configuration -> configuration.resolve().joinToString(" ") { it.name } }) } - duplicatesStrategy = DuplicatesStrategy.WARN } - registerDokkaArtifactPublication("dokkaMavenPlugin") { artifactId = "dokka-maven-plugin" } diff --git a/runners/maven-plugin/pom.template.xml b/runners/maven-plugin/pom.template.xml index 01ad60d2..b4795112 100644 --- a/runners/maven-plugin/pom.template.xml +++ b/runners/maven-plugin/pom.template.xml @@ -12,6 +12,7 @@ <packaging>maven-plugin</packaging> <properties> <maven.version>${mavenVersion}</maven.version> + <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> </properties> <build> <plugins> @@ -21,10 +22,35 @@ <version>${mavenPluginToolsVersion}</version> <configuration> <helpPackageName>org.jetbrains.dokka.maven</helpPackageName> + <skipErrorNoDescriptorsFound>true</skipErrorNoDescriptorsFound> </configuration> + <executions> + <execution> + <id>default-descriptor</id> + <goals> + <goal>descriptor</goal> + </goals> + <phase>process-classes</phase> + </execution> + <execution> + <id>help-descriptor</id> + <goals> + <goal>helpmojo</goal> + </goals> + <phase>process-classes</phase> + </execution> + </executions> </plugin> </plugins> <directory>./</directory> <outputDirectory>./classes/java/main</outputDirectory> </build> + <dependencies> + <dependency> + <groupId>org.apache.maven.plugin-tools</groupId> + <artifactId>maven-plugin-annotations</artifactId> + <version>${mavenPluginToolsVersion}</version> + <scope>provided</scope> + </dependency> + </dependencies> </project> |