Robert Burke
Robert Burke

Reputation: 33

No basedir set from native-maven-plugin

I'm having some trouble getting the maven native plugin to work. The problem is that I'm getting an IllegalStateException: "No basedir set" when compiling. The stacktrace follows:

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

The native-ipc pom.xml is:

<?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>

And the parent pom is simply:

<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>

I feel like I'm missing something obvious. Any help would be appreciated.

-RB

Upvotes: 0

Views: 1437

Answers (2)

Jim Brentnell
Jim Brentnell

Reputation: 1

The problem is caused by not having a <directory> defined inside a <source>. In the problem above, you have:

<sources>
...
    <source>
        <includes>
            <include>/Library/Java/...</include>
            <include>/Library/Java/...</include>
        <includes>
    <source>
...
<sources>

Notice there is no <directory> tag!

I had a similar problem where I was using a Maven property in the directory tag. Unfortunately, the Maven property was undefined. Yes, it took a while to chase that down.

I hope this helps.

Upvotes: 0

Robert Burke
Robert Burke

Reputation: 33

If anyone else runs into this, the problem seemed to be tag order. Ad moved the original pom.xml into a macosx sub-module. The following maven file worked.

<?xml version="1.0" encoding="UTF-8"?>
<project>
    <modelVersion>4.0.0</modelVersion>

    <!-- @todo Break this out into a parent pom and child modules once we have multiple platforms to support. -->

    <groupId>com.discovix</groupId>
    <artifactId>macosx</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>jnilib</packaging>

    <name>JNI - MacOSX</name>

    <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>
                      <jdkIncludePath>/Library/Java/JavaVirtualMachines/jdk1.7.0_11.jdk/Contents/Home/include</jdk IncludePath>
                    <javahOS>macosx</javahOS>
                    <javahOutputDirectory>${project.build.directory}/custom-javah</javahOutputDirectory>
                    <!-- demonstrate we can override location of javah generate directory and use javah -o option instead" -->
                    <javahOutputFileName>posix-ipc.h</javahOutputFileName>
                    <javahClassNames>
                    <javahClassName>com.discovix.projects.glimmerglass.jni.posix.IPC</javahClassName>
                    </javahClassNames>

                    <compilerProvider>generic</compilerProvider>
                    <compilerStartOptions>
                        <compilerStartOption>-fPIC -O</compilerStartOption>
                    </compilerStartOptions>
                    <sources>
                        <source>
                            <directory>../src/main/native</directory>
                            <fileNames>
                                <fileName>ipc.cpp</fileName>
                            </fileNames>
                        </source>
                        <source>
                            <directory>/Library/Java/JavaVirtualMachines/jdk1.7.0_11.jdk/Contents/Home/include/darwin</directory>
                            <includes>
                                <include>**/*.h</include>
                            </includes>
                        </source>
                    </sources>

                    <linkerStartOptions>
                        <linkerStartOption>-prebind -dynamiclib -lc -ldl</linkerStartOption>
                    </linkerStartOptions>

                </configuration>
            </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>

Upvotes: 0

Related Questions