Mathias Conradt
Mathias Conradt

Reputation: 28705

Maven build for Grails 2.2.0 app fails with JDK 1.7: Could not find artifact com.sun:tools:jar:1.6

(Updated question title due to updated question/problem, please see my update notes at the bottom!):

I have a Grails 2.2.0 project, created the pom.xml for it via 'grails create-pom com.mycompany'.

pom.xml: http://pastebin.com/AVahZjZF

Without modifications to the pom.xml, I run 'mvn package' with JDK 1.7 and getting the error below, while with JDK 1.6 it would work fine.

$ java -version
java version "1.7.0_11"
Java(TM) SE Runtime Environment (build 1.7.0_11-b21)
Java HotSpot(TM) 64-Bit Server VM (build 23.6-b04, mixed mode)

$ mvn -version
Apache Maven 3.0.3 (r1075438; 2011-03-01 01:31:09+0800)
Maven home: /usr/share/maven
Java version: 1.7.0_11, vendor: Oracle Corporation
Java home: /Library/Java/JavaVirtualMachines/jdk1.7.0_11.jdk/Contents/Home/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "mac os x", version: "10.7.4", arch: "x86_64", family: "mac"

$ echo $JAVA_HOME
/Library/Java/JavaVirtualMachines/jdk1.7.0_11.jdk/Contents/Home

$ mvn package
[INFO] Scanning for projects...
[ERROR] The build could not read 1 project -> [Help 1]
[ERROR]   
[ERROR]   The project com.company:company-projectname:0.1 (/Users/myuser/Projects/com.company.web/pom.xml) has 2 errors
[ERROR]     Unresolveable build extension: Plugin org.grails:grails-maven-plugin:2.2.0 or one of its dependencies could not be resolved: Could not find artifact com.sun:tools:jar:1.6 at specified path /Library/Java/JavaVirtualMachines/jdk1.7.0_11.jdk/Contents/Home/jre/bundle/Classes/classes.jar -> [Help 2]
[ERROR]     Unknown packaging: grails-app @ line 8, column 16
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/ProjectBuildingException
[ERROR] [Help 2] http://cwiki.apache.org/confluence/display/MAVEN/PluginResolutionException

I see that the java version is set to 1.6 in grails-maven-plugin-2.2.0.pom, thus my question now: how to make the maven build for my grails project work with JDK 1.7? It looks as if the correct source and target level is set in maven-compiler-plugin (set to 1.6).

Folder ~/.m2/repository/grails-maven-plugin:

enter image description here

My environment:

Relevant java tools section in my pom.xml:

<profiles>
    <profile>
        <id>tools</id>
        <activation>
            <property>
                <name>java.vendor</name>
                <value>Sun Microsystems Inc.</value>
            </property>
        </activation>
        <dependencies>
            <dependency>
                <groupId>com.sun</groupId>
                <artifactId>tools</artifactId>
                <version>${java.version}</version>
                <scope>system</scope>
                <systemPath>${java.home}/../lib/tools.jar</systemPath>
            </dependency>
        </dependencies>
    </profile>
</profiles>

Upvotes: 2

Views: 4271

Answers (3)

Nicholas Albion
Nicholas Albion

Reputation: 3284

The problem is that the grails-maven-plugin says that it needs something in JDK6:

tail -n20 ~/.m2/repository/org/grails/grails-maven-plugin/2.0.3/grails-maven-plugin-2.0.3.pom
    <profile>
        <id>jdk_mac</id>
        <activation>
            <os>
                <family>mac</family>
            </os>
        </activation>
        <dependencies>
            <dependency>
                <groupId>com.sun</groupId>
                <artifactId>tools</artifactId>
                <version>1.6</version>
                <scope>system</scope>
                <systemPath>${java.home}/bundle/Classes/classes.jar</systemPath>
            </dependency>
        </dependencies>
    </profile>
</profiles>

The solution is to copy the JDK6 classes.jar into your current JDK. Fortunately, JDK7 uses a different directory structure, so there should not be any conflict.

sudo mkdir -p /Library/Java/JavaVirtualMachines/jdk1.7.0_79.jdk/Contents/Home/jre/bundle/Classes
sudo cp /System/Library/Frameworks/JavaVM.framework/Versions/1.6/Classes/classes.jar /Library/Java/JavaVirtualMachines/jdk1.7.0_79.jdk/Contents/Home/jre/bundle/Classes/

Upvotes: 0

rimero
rimero

Reputation: 2383

UPDATE

As mentioned by @Mathias this was a bug in the Grails Maven plugin. The issue has been fixed and all works fine in Grails 2.2.1.


I can definitely use mvn package here with Grails 2.2.0 from Homebrew, *GRAILS_HOME* unset.

My configuration is Maven 3.0.3 with Grails 2.2.0, on OSX.

I created a "blank" vanilla application without any trouble and packaged it.

grails create-app stf && cd stf
grails create-pom com.rimerosolutions.grails
mvn package

In my pom.xml, the version of grails-maven-plugin is set to ${grails.version}.

I'm running OSX, looks like you're running it too.

  • Are you using a private maven repository? If so, try to double-check the grails-maven-plugin artifact in there.
  • If not, just try to clear your ~/.m2/repository contents for grails-maven-plugin. rm -rf that specific plugin cache.

Upvotes: 2

Mathias Conradt
Mathias Conradt

Reputation: 28705

It seems to be a known issue and reportedly still happening in Grails 2.2.0 on Mac OS X.

http://jira.grails.org/browse/MAVEN-186

Upvotes: 3

Related Questions