Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions docs/src/docs/asciidoc/maven-plugin.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,43 @@ For example, to build a native image named `myapp` that uses `org.example.ClassN
Most of the aforementioned properties can also be set on the command line as a part of Maven invocation. For example, if you want to temporarily enable verbose mode, you can append `-Dverbose` to your Maven command.
====

[[maven-site-build-report]]
== Maven Site Build Report

If your native build already emits a GraalVM Native Image build report, you can publish it as a page in the Maven-generated site.
Add the plugin to the `<reporting>` section:

[source,xml, role="multi-language-sample"]
----
<reporting>
<plugins>
<plugin>
<groupId>org.graalvm.buildtools</groupId>
<artifactId>native-maven-plugin</artifactId>
<version>${native.maven.plugin.version}</version>
<reportSets>
<reportSet>
<reports>
<report>build-report</report>
</reports>
</reportSet>
</reportSets>
</plugin>
</plugins>
</reporting>
----

The report goal copies the generated Native Image build report HTML into the Maven site output and also copies `dynamic-access-metadata.json` when it is present.

To make sure the source build report exists before `site` runs, enable one of the GraalVM build report switches in the native build configuration and run the native build before site generation:

[source,bash, role="multi-language-sample"]
----
./mvnw -Pnative package site
----

Supported Native Image build report switches are `--emit build-report` and `-H:+BuildReport`.

[[native-image-tracing-agent]]
== Native Image Tracing Agent

Expand Down
4 changes: 4 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ metadataRepository = "1.0-M1"
spock = "2.1-groovy-3.0"
maven = "3.9.9"
mavenAnnotations = "3.6.4"
mavenReporting = "4.0.0"
mavenEmbedder = "3.9.9"
mavenResolver = "1.9.22"
doxia = "2.1.0"
graalvm = "23.0.2"
openjson = "1.0.13"
junitPlatform = "1.13.0"
Expand Down Expand Up @@ -47,6 +49,8 @@ maven-pluginApi = { module = "org.apache.maven:maven-plugin-api", version.ref =
maven-pluginAnnotations = { module = "org.apache.maven.plugin-tools:maven-plugin-annotations", version.ref = "mavenAnnotations" }
maven-core = { module = "org.apache.maven:maven-core", version.ref = "maven" }
maven-artifact = { module = "org.apache.maven:maven-artifact", version.ref = "maven" }
maven-reporting-api = { module = "org.apache.maven.reporting:maven-reporting-api", version.ref = "mavenReporting" }
maven-doxia-sink-api = { module = "org.apache.maven.doxia:doxia-sink-api", version.ref = "doxia" }
maven-compat = { module = "org.apache.maven:maven-compat", version.ref = "maven" }
maven-embedder = { module = "org.apache.maven:maven-embedder", version.ref = "mavenEmbedder" }
maven-resolver-basic = { module = "org.apache.maven.resolver:maven-resolver-connector-basic", version.ref = "mavenResolver"}
Expand Down
6 changes: 6 additions & 0 deletions native-maven-plugin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ dependencies {
compileOnly(libs.maven.pluginApi)
compileOnly(libs.maven.core)
compileOnly(libs.maven.artifact)
compileOnly(libs.maven.reporting.api)
compileOnly(libs.maven.doxia.sink.api)
compileOnly(libs.maven.pluginAnnotations)

mavenEmbedder(libs.maven.embedder)
Expand All @@ -83,6 +85,8 @@ dependencies {
testImplementation(libs.test.spock)
testImplementation(libs.maven.core)
testImplementation(libs.maven.artifact)
testImplementation(libs.maven.reporting.api)
testImplementation(libs.maven.doxia.sink.api)
testImplementation(libs.jetty.server)

testFixturesImplementation(libs.test.spock)
Expand All @@ -94,6 +98,8 @@ dependencies {
functionalTestCommonRepository("org.graalvm.internal:library-with-reflection")

functionalTestImplementation(libs.test.spock)
functionalTestImplementation(libs.maven.reporting.api)
functionalTestImplementation(libs.maven.doxia.sink.api)
functionalTestRuntimeOnly(libs.slf4j.simple)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,4 +143,73 @@ class JavaApplicationFunctionalTest extends AbstractGraalVMMavenFunctionalTest {
outputContains "Args file written to: target" + File.separator + "native-image"
}

def "can publish the native build report into the Maven site"() {
withSample("java-application")
configureNativeBuildSiteReport()
file("target/assets").mkdirs()
file("target/example-app-build-report.html").text = '''
<html>
<head>
<title>Build report</title>
<link rel="stylesheet" href="assets/report.css">
<script src="assets/report.js"></script>
</head>
<body>
<h1>Native Image Build Report</h1>
<p>Reachability summary</p>
</body>
</html>
'''
file("target/assets/report.css").text = "body { background: #fff; }"
file("target/assets/report.js").text = "console.log('build-report');"
file("target/dynamic-access-metadata.json").text = '{"libraries":[]}'

when:
mvn 'site'

then:
buildSucceeded
file("target/site/native-build-report/index.html").text.contains("Native Image Build Report")
file("target/site/native-build-report/assets/report.css").exists()
file("target/site/native-build-report/assets/report.js").exists()
file("target/site/native-build-report/dynamic-access-metadata.json").exists()
}

def "can render a helpful fallback page when the native build report is missing"() {
withSample("java-application")
configureNativeBuildSiteReport()

when:
mvn 'site'

then:
buildSucceeded
file("target/site/native-build-report/index.html").text.contains("No GraalVM Native Image build report was found")
file("target/site/native-build-report/index.html").text.contains("--emit build-report")
file("target/site/native-build-report/index.html").text.contains("-H:+BuildReport")
}

private void configureNativeBuildSiteReport() {
def pom = file("pom.xml")
pom.text = pom.text.replace("</project>", '''
<reporting>
<plugins>
<plugin>
<groupId>org.graalvm.buildtools</groupId>
<artifactId>native-maven-plugin</artifactId>
<version>${native.maven.plugin.version}</version>
<reportSets>
<reportSet>
<reports>
<report>build-report</report>
</reports>
</reportSet>
</reportSets>
</plugin>
</plugins>
</reporting>
</project>
''')
}

}
Loading