native-build-tools icon indicating copy to clipboard operation
native-build-tools copied to clipboard

Document resources configuration support in plugins

Open sbrannen opened this issue 3 years ago • 4 comments

The documentation for the Gradle and Maven plugins currently does not cover support for configuring resources or auto-detection of resources.

sbrannen avatar Dec 06 '21 15:12 sbrannen

There are many configuration options without description. I guess resourceIncludedPatterns that's the option wich should do it, but it doesn't matter what i configure as nearly everything gets ignored. @sbrannen maybe the following helps?

<configuration>
    <!-- IGNORED -->
    <resourceIncludedPatterns>.*</resourceIncludedPatterns>
    <!-- WORKS -->
    <buildArgs>-H:IncludeResources=.*</buildArgs>
</configuration>

YunaBraska avatar Dec 07 '21 20:12 YunaBraska

Thanks @YunaBraska this fixed it for me as well.

I noticed that with ".*" the resulting binary grew 10x in size, even though I only have one small toml file in my resources. So I switched the expression to

              <buildArgs>-H:IncludeResources='.*toml$'</buildArgs>

which did the trick without exploding the size of the image.

ngeor avatar Apr 09 '22 08:04 ngeor

according to maven docs https://maven.apache.org/guides/mini/guide-configuring-plugins.html#mapping-collection-types it must be like this:

<configuration>
	<resourceIncludedPatterns>
		<resourceIncludedPattern>application.properties</resourceIncludedPattern>
	</resourceIncludedPatterns>
</configuration>

however it doesn't work for me too. I'm reading application.properties with getResourceAsStream, so java-agent was able to find it added the following to the resource-config.json:

{
    "pattern":"\\Qapplication.properties\\E"
  }

So i tried it the same for the maven plugin:

<configuration>
	<resourceIncludedPatterns>
		<resourceIncludedPattern>\\Qapplication.properties\\E</resourceIncludedPattern>
	</resourceIncludedPatterns>
</configuration>

but it still doesn't work. Meanwhile i'll leave it with the java-agent to find the file for me, it's fine for me. But the maven plugin definitely has some problem... or it's just badly documented as it is actually stated in the header of the issue

bdshadow avatar Dec 19 '23 00:12 bdshadow

I have finally found it. It is not described anywhere, but is present in the samples in this repo: https://github.com/graalvm/native-build-tools/blob/master/samples/java-application-with-resources/pom.xml#L102

So you need to execute the generateResourceConfig goal before the build. The following works for me

<plugin>
	<groupId>org.graalvm.buildtools</groupId>
	<artifactId>native-maven-plugin</artifactId>
	<version>${native.maven.plugin.version}</version>
	<extensions>true</extensions>
	<executions>
		<execution>
			<id>build-native</id>
			<goals>
				<goal>generateResourceConfig</goal>
				<goal>build</goal>
			</goals>
			<phase>package</phase>
		</execution>
		<execution>
			<id>test-native</id>
			<goals>
				<goal>test</goal>
			</goals>
			<phase>test</phase>
		</execution>
	</executions>
	<configuration>
		<fallback>false</fallback>
		<resourceIncludedPatterns>
			<pattern>application.properties</pattern>
		</resourceIncludedPatterns>
	</configuration>
</plugin>

bdshadow avatar Jan 04 '24 22:01 bdshadow