Skip to content

native-image-maven-plugin UnsupportedOperationException for project with com.oracle.substratevm:svm:1.0.0-rc12 as dependency #1003

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

Closed
Jurrie opened this issue Feb 24, 2019 · 5 comments
Assignees

Comments

@Jurrie
Copy link

Jurrie commented Feb 24, 2019

I am using the native-image-maven-plugin to make a native image for a Maven project. This project needs the com.oracle.substratevm:svm:1.0.0-rc12 dependency, because I need to use the com.oracle.svm.core.annotate.* annotations. But that dependency, by default, transitively includes dependencies that are not JAR files. For example, it depends on com.oracle.substratevm:svm-hosted-native-linux-amd64:1.0.0-rc12 which is a *.tar.gz file.

The native-image-maven-plugin fetches all dependencies, and tries to parse them as JAR files. This fails for com.oracle.substratevm:svm-hosted-native-linux-amd64:1.0.0-rc12, and results in a UnsupportedOperationException.

Work-around

Quick work-around is to exclude all non-JAR dependencies:

<dependency>
	<groupId>com.oracle.substratevm</groupId>
	<artifactId>svm</artifactId>
	<version>1.0.0-rc12</version>
	<exclusions>
		<exclusion>
			<groupId>com.oracle.substratevm</groupId>
			<artifactId>svm-hosted-native-linux-amd64</artifactId>
		</exclusion>
		<exclusion>
			<groupId>com.oracle.substratevm</groupId>
			<artifactId>svm-hosted-native-darwin-amd64</artifactId>
		</exclusion>
		<exclusion>
			<groupId>com.oracle.substratevm</groupId>
			<artifactId>svm-hosted-native-windows-amd64</artifactId>
		</exclusion>
		<exclusion>
			<groupId>org.graalvm.truffle</groupId>
			<artifactId>truffle-nfi-native-darwin-amd64</artifactId>
		</exclusion>
		<exclusion>
			<groupId>org.graalvm.truffle</groupId>
			<artifactId>truffle-nfi-native-linux-amd64</artifactId>
		</exclusion>
	</exclusions>
</dependency>

Alternatively, if you do not require any transitive dependency, you can use:

<dependency>
	<groupId>com.oracle.substratevm</groupId>
	<artifactId>svm</artifactId>
	<version>1.0.0-rc12</version>
	<exclusions>
		<exclusion>
			<groupId>*</groupId>
			<artifactId>*</artifactId>
		</exclusion>
	</exclusions>
</dependency>

(I feel the com.oracle.svm.core.annotate.* classes should be in a separate artifact, but that's a different story.)

How to reproduce

Change the pom.xml of com.oracle.substratevm:native-image-maven-plugin-test to include the following dependency:

<dependencies>
	<dependency>
		<groupId>com.oracle.substratevm</groupId>
		<artifactId>svm</artifactId>
	<version>1.0.0-rc12</version>
	</dependency>
</dependencies>

And then run mvn verify for that project. Output will be:

[ERROR] Failed to execute goal com.oracle.substratevm:native-image-maven-plugin:1.0.0-rc12:native-image (default) on project native-image-maven-plugin-test: Execution default of goal com.oracle.substratevm:native-image-maven-plugin:1.0.0-rc12:native-image failed.: UnsupportedOperationException -> [Help 1]
Jurrie added a commit to Jurrie/graal that referenced this issue Feb 25, 2019
@olpaw
Copy link
Member

olpaw commented Feb 25, 2019

The right approach to use com.oracle.substratevm:svm is to define

    <dependency>
      <groupId>com.oracle.substratevm</groupId>
      <artifactId>svm</artifactId>
      <version>1.0.0-rc12</version>
      <scope>provided</scope>
    </dependency>

The key here is that you use <scope>provided</scope>. This ensures that com.oracle.substratevm:svm will not be transitively folded into your uber-jar.

@Jurrie
Copy link
Author

Jurrie commented Feb 25, 2019

Right, that does make sense :) Still, I feel it's a bug that the Maven plugin will try to parse any artifact as a JAR. (It's only illustrated by the com.oracle.substratevm:svm artifact, it's not limited to it.)

@olpaw
Copy link
Member

olpaw commented Feb 25, 2019

Still, I feel it's a bug that the Maven plugin will try to parse any artifact as a JAR

Makes sense. I will add a check that issues a warning for non-jar files. Or if you like I can hold off until you have completed the OCA signing procedure and we merge your change instead.

@Jurrie
Copy link
Author

Jurrie commented Feb 25, 2019

I hope you can wait for the OCA procedure to finish then :)

@olpaw
Copy link
Member

olpaw commented Mar 1, 2019

Fixed on master 8020b64

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants