0

It has been few weeks since I build anything in maven, and I just tried to build one of the projects and it gives me this error. I try with multiple project and they are throwing same error:

Execution default of goal org.codehaus.mojo:aspectj-maven-plugin:1.8:compile failed: Plugin org.codehaus.mojo:aspectj-maven-plugin:1.8 or one of its dependencies could not be resolved: Could not find artifact com.sun:tools:jar:15.0.2 at specified path /usr/local/Cellar/openjdk/15.0.2/libexec/openjdk.jdk/Contents/Home/../lib/tools.jar -> [Help 1]

How can I resolve this error? I can't even run mvn install -DskipTests or mvn package.

I am on JDK version 8.

Edit: here is my plugin from pom:

             <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>aspectj-maven-plugin</artifactId>
                <version>${aspectj-maven-plugin.version}</version>
                <configuration>
                    <complianceLevel>${java.version}</complianceLevel>
                    <source>${java.version}</source>
                    <target>${java.version}</target>
                    <showWeaveInfo>true</showWeaveInfo>
                    <verbose>true</verbose>
                    <aspectLibraries>
                        <dependency>
                            <groupId>com.jcabi</groupId>
                            <artifactId>jcabi-aspects</artifactId>
                        </dependency>
                    </aspectLibraries>
                </configuration>
                <executions>
                    <execution>
                        <goals>
                            <goal>compile</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

java version = 1.8 aspectj-maven-plugin.version = 1.8

EDIT: I pull this project from the repo, which means it works on other people's computer/on jenkins. I believe this is something to do with my local computer. It also gives me same error if I use terminal.

Jonathan Hagen
  • 580
  • 1
  • 6
  • 29
  • Please check this question: https://stackoverflow.com/questions/21596416/could-not-find-dependencies-for-aspectj-maven-plugin – donnadulcinea Jul 16 '21 at 20:16
  • I don't think this resolves my issue – Jonathan Hagen Jul 16 '21 at 20:17
  • Can you please check `java -version`? – g00se Jul 16 '21 at 20:42
  • 1
    Looks Like you are using jdk 15: Could not find artifact com.sun:tools:jar:15.0.2 at specified path /usr/local/Cellar/openjdk/15.0.2/libexec/openjdk.jdk/Contents/Home/../lib/tools.jar -> [Help 1] have you checked your JAVA_HOME? – Michael Katt Jul 17 '21 at 05:35
  • @g00se this is my java version openjdk version "1.8.0_212" OpenJDK Runtime Environment (AdoptOpenJDK)(build 1.8.0_212-b04) OpenJDK 64-Bit Server VM (AdoptOpenJDK)(build 25.212-b04, mixed mode) – Jonathan Hagen Jul 19 '21 at 12:57
  • I'm not a MacOS person but I noticed that weird /usr/local/Cellar directory. afaics that's to do with something called 'Homebrew'. There's something fishy about it all since the error message is mentioning version 15. *Are* you using Homebrew? – g00se Jul 19 '21 at 13:07
  • @g00se yes I use homebrew to install necessary components – Jonathan Hagen Jul 19 '21 at 13:26
  • @MichaelKatt `which java` returns `/usr/bin/java` – Jonathan Hagen Jul 19 '21 at 13:29

1 Answers1

0

I found the answer after more research. As @Michael Katt mentioned in the comment, my JAVA_HOME wasn't properly set up. When I did which java, it gave me /usr/bin/java, but when I did echo $JAVA_HOME, it gave me nothing.

So with help of other colleague, I did vi ~/.bash_profile and added export JAVA_HOME=$(/usr/libexec/java_home). Not exactly sure why, but it is something to do with matching it with my jdk in my project structure which has /Library/Java/JavaVirtualMachines/adoptopenjdk-8.jdk...

I opened new shell and typed echo $JAVA_HOME and it gives me /Library/Java/JavaVirtualMachines/adoptopenjdk-8.jdk/Contents/Home. My project build/compiles now.

I am still not sure how $(/usr/libexec/java_home) translated to /Library/Java/JavaVirtualMachines/adoptopenjdk-8.jdk...

Jonathan Hagen
  • 580
  • 1
  • 6
  • 29