Skip to content

Commit

Permalink
Fix native-image build-time initialization (helidon-io#6426)
Browse files Browse the repository at this point in the history
* Fix native-image build-time initialization

- Isolate the use of --static with to Linx only.
- Add a native-image.properties file in archetypes for all generated project

Fixes helidon-io#6284

* specify build-args for the build-native-image execution, and ensure it's merged
  • Loading branch information
romain-grecourt authored Mar 17, 2023
1 parent 4d41a39 commit 695cd6e
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 4 deletions.
28 changes: 26 additions & 2 deletions applications/parent/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
<version>3.1.3-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<groupId>io.helidon.applications</groupId>
<artifactId>helidon-applications</artifactId>
<packaging>pom</packaging>
<name>Helidon Applications Parent</name>
Expand Down Expand Up @@ -201,7 +200,6 @@
<buildArgs>
<!-- Some native image features use the svm dependencies which require additional exports -->
<arg>--add-exports=org.graalvm.nativeimage.builder/com.oracle.svm.core.configure=ALL-UNNAMED</arg>
<arg>--static</arg>
</buildArgs>
</configuration>
</execution>
Expand All @@ -211,6 +209,32 @@
</pluginManagement>
</build>
<profiles>
<profile>
<id>linux-native</id>
<activation>
<os>
<family>Linux</family>
</os>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.graalvm.buildtools</groupId>
<artifactId>native-maven-plugin</artifactId>
<executions>
<execution>
<id>build-native-image</id>
<configuration>
<buildArgs combine.children="append">
<arg>--static</arg>
</buildArgs>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>helidon-cli</id>
<activation>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Args=--initialize-at-build-time={{package}}
35 changes: 35 additions & 0 deletions archetypes/helidon/src/main/archetype/common/native-image.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (c) 2023 Oracle and/or its affiliates.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<archetype-script xmlns="https://helidon.io/archetype/2.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="https://helidon.io/archetype/2.0 https://helidon.io/xsd/archetype-2.0.xsd">

<output>
<transformation id="native-image">
<replace regex="__dir__" replacement="${groupId}/${artifactId}"/>
</transformation>

<templates engine="mustache" transformations="native-image,mustache">
<directory>files</directory>
<includes>
<include>**/native-image/**</include>
</includes>
</templates>
</output>
</archetype-script>
3 changes: 2 additions & 1 deletion archetypes/helidon/src/main/archetype/common/packaging.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (c) 2022 Oracle and/or its affiliates.
Copyright (c) 2022, 2023 Oracle and/or its affiliates.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand All @@ -20,6 +20,7 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="https://helidon.io/archetype/2.0 https://helidon.io/xsd/archetype-2.0.xsd">

<exec src="native-image.xml"/>
<step name="Packaging and Deployment" optional="true">
<exec src="docker.xml"/>
<inputs>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright (c) 2019, 2023Oracle and/or its affiliates.
# Copyright (c) 2019, 2023 Oracle and/or its affiliates.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down

0 comments on commit 695cd6e

Please sign in to comment.