JavaHintsTestMaven

Revision as of 18:11, 9 July 2012 by Jglick (Talk | contribs)
(diff) ← Older revision | Current revision (diff) | Newer revision → (diff)

To use NB 7.2's org.netbeans.modules.java.hints.test.api.HintTest in a Maven NBM project, use the "Java Hint" template to add basic dependencies and create sample code, and then add the following snippets to existing sections of your POM (add plugin <version>s as needed):

    <properties>
        ...
        <endorsed.dir>${project.build.directory}/endorsed</endorsed.dir>
    </properties>
    <dependencies>
        ...
        <dependency>
            <groupId>org.netbeans.modules</groupId>
            <artifactId>org-netbeans-lib-nbjavac</artifactId>
            <version>${netbeans.version}</version>
            <scope>test</scope>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            ...
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <executions>
                    <execution>
                        <id>endorsed</id>
                        <phase>validate</phase>
                        <goals>
                            <goal>copy</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <outputDirectory>${endorsed.dir}</outputDirectory>
                    <silent>true</silent>
                    <artifactItems>
                        <artifactItem>
                            <groupId>org.netbeans.api</groupId>
                            <artifactId>org-netbeans-libs-javacapi</artifactId>
                            <version>${netbeans.version}</version>
                        </artifactItem>
                        <artifactItem>
                            <groupId>org.netbeans.external</groupId>
                            <artifactId>nb-javac-api</artifactId>
                            <version>${netbeans.version}</version>
                        </artifactItem>
                        <artifactItem>
                            <groupId>org.netbeans.modules</groupId>
                            <artifactId>org-netbeans-libs-javacimpl</artifactId>
                            <version>${netbeans.version}</version>
                        </artifactItem>
                        <artifactItem>
                            <groupId>org.netbeans.external</groupId>
                            <artifactId>nb-javac-impl</artifactId>
                            <version>${netbeans.version}</version>
                        </artifactItem>
                    </artifactItems>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <compilerArguments>
                        <endorseddirs>${endorsed.dir}</endorseddirs>
                    </compilerArguments>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <configuration>
                    <argLine>-Djava.endorsed.dirs=${endorsed.dir}</argLine>
                </configuration>
            </plugin>
        </plugins>
    </build>

Discussion:

  1. The explicit dep on org.netbeans.modules:org-netbeans-lib-nbjavac is needed for classes like CancelAbort transitively from org.netbeans.api:org-netbeans-modules-java-source. This is because nbm:populate-repository currently omits nonpublic dependencies of public API modules from the generated Maven dependency list - which is fine for minimizing your compile-time classpath, but breaks transitivity for unit tests.
  2. The NetBeans versions of the Javac API & implementation are needed so that new language features can be developed even against older JDKs. Note that the NetBeans modules are library wrappers, so you need the actual library too (and dependency:copy has no way of grabbing transitive dependencies).
  3. http://jira.codehaus.org/browse/MNG-4752 explains why the manual definition of java.endorsed.dirs is needed. http://maven.apache.org/plugins/maven-surefire-plugin/examples/system-properties.html mentions that Surefire can only accept argLine, not systemProperties.
Not logged in. Log in, Register

By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2012, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo