我在让 maven 本机插件工作时遇到了一些麻烦。问题是我在编译时收到 IllegalStateException: "No basedir set"。堆栈跟踪如下:
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.codehaus.mojo:native-maven-plugin:1.0-alpha-7:compile (default-compile) on project native-ipc: Execution default-compile of goal org.codehaus.mojo:native-maven-plugin:1.0-alpha-7:compile failed: No basedir set
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:225)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59)
at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:319)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:156)
at org.apache.maven.cli.MavenCli.execute(MavenCli.java:537)
at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:196)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:141)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:290)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:230)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:409)
at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:352)
Caused by: org.apache.maven.plugin.PluginExecutionException: Execution default-compile of goal org.codehaus.mojo:native-maven-plugin:1.0-alpha-7:compile failed: No basedir set
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:110)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:209)
... 19 more
Caused by: java.lang.IllegalStateException: No basedir set
at org.codehaus.plexus.util.DirectoryScanner.scan(DirectoryScanner.java:286)
at org.codehaus.mojo.natives.NativeSources.getFiles(NativeSources.java:183)
at org.codehaus.mojo.natives.NativeSources.getAllSourceFiles(NativeSources.java:240)
at org.codehaus.mojo.natives.plugin.NativeCompileMojo.execute(NativeCompileMojo.java:167)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:101)
... 20 more
native-ipc pom.xml 是:
<?xml version="1.0" encoding="UTF-8"?>
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>native-ipc</groupId>
<artifactId>native-ipc</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>so</packaging>
<properties>
<basedir>${project.basedir}</basedir>
</properties>
<parent>
<groupId>com.discovix</groupId>
<artifactId>discovix-parent</artifactId>
<version>1.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>native-maven-plugin</artifactId>
<extensions>true</extensions>
<configuration>
<javahOS>MacOS</javahOS>
<sources>
<source>
<directory>src/main/cpp</directory>
<fileNames>
<fileName>ipc.cpp</fileName>
</fileNames>
<includes>
<include>${java.home}/include/*</include>
</includes>
</source>
<source>
<includes>
<include>/Library/Java/JavaVirtualMachines/jdk1.7.0_11.jdk/Contents/Home/include/</include>
<include>/Library/Java/JavaVirtualMachines/jdk1.7.0_11.jdk/Contents/Home/include/darwin/</include>
</includes>
</source>
</sources>
<linkerStartOptions>
<linkerStartOption>-shared -Wall</linkerStartOption>
</linkerStartOptions>
<compilerProvider>generic-classic</compilerProvider>
<compilerExecutable>g++</compilerExecutable>
</configuration>
<executions>
<execution>
<id>javah</id>
<phase>generate-sources</phase>
<configuration>
<javahOS>MacOS</javahOS>
<javahProvider>default</javahProvider>
<javahOutputDirectory>${project.build.directory}/custom-javah</javahOutputDirectory>
<workingDirectory>${project.basedir}</workingDirectory>
<javahClassNames>
<javahClassName>com.discovix.projects.glimmerglass.jni.posix.IPC</javahClassName>
</javahClassNames>
<goals>
<goal>javah</goal>
</goals>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>com.discovix</groupId>
<artifactId>network-analyzer</artifactId>
<version>1.0-SNAPSHOT</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
</dependencies>
</project>
父 pom 很简单:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.discovix</groupId>
<artifactId>discovix-parent</artifactId>
<packaging>pom</packaging>
<version>1.0-SNAPSHOT</version>
<name>Discovix GlimmerGlass</name>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
<modules>
<module>network-analyzer</module>
<module>native-ipc</module>
<module>generators</module>
</modules>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>native-maven-plugin</artifactId>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
我觉得我错过了一些明显的东西。任何帮助,将不胜感激。
-RB