I had a Maven project, which I then switched to Gradle. I am now attempting to compile the Gradle project, but it isn't compiling, even if it was building and compiling successfully when I used Maven.
I ran gradle init
to convert my project to Gradle and it stopped compiling and gave me the "cannot find symbol" errors. It seems as though Gradle cannot find many classes, including the Main
class.
I have effectively read through the post: What does a "Cannot find symbol" or "Cannot resolve symbol" error mean? and I was unable to fix my issue. I know it's a compilation error, but I don't know what's causing it. I didn't change the code when I switched from Maven to Gradle, only the build files.
Here is an example of one of the errors:
Main instance = Main.getInstance();
^
symbol: method getInstance()
location: class Main
Note: the build is a multi-project build. It has several subprojects. Here is the mother build.gradle file:
plugins {
id "java"
id "com.github.johnrengelman.shadow" version "7.1.2"
id "war"
}
group "net.pixlies"
version "1.0-SNAPSHOT"
java {
toolchain {
languageVersion = JavaLanguageVersion.of(17)
}
}
subprojects {
compileJava.options.encoding = "UTF-8"
apply plugin: "java"
apply plugin: "war"
apply plugin: "com.github.johnrengelman.shadow"
compileJava {
sourceCompatibility = 17
targetCompatibility = 17
}
}
repositories {
mavenCentral()
maven { url "https://repo.purpurmc.org/snapshots/" }
maven { url "https://repo.extendedclip.com/content/repositories/placeholderapi/" }
maven { url "https://repo.aikar.co/content/groups/aikar/" }
maven { url "https://repo.dmulloy2.net/repository/public/" }
}
dependencies {
implementation "org.mongodb:mongo-java-driver:3.12.11"
implementation "commons-io:commons-io:2.11.0"
implementation "co.aikar:acf-paper:0.5.1-SNAPSHOT"
implementation "org.ocpsoft.prettytime:prettytime:5.0.3.Final"
implementation "commons-lang:commons-lang:2.6"
}
Here is the settings.gradle file:
pluginManagement {
repositories {
gradlePluginPortal()
maven { url "https://papermc.io/repo/repository/maven-public/" }
}
}
rootProject.name = 'version-two'
include(':PixliesCore')
include(':LobbyModule')
include(':MiniMick')
include(':ProtoBusiness')
include(':PixliesFun')
include(':Nations')
include(':DiploMaurice')
include(':PixliesProxyCore')
The PixliesCore project is having these issues with the "Cannot find symbol" error. Here is the PixliesCore
subproject build.gradle file:
plugins {
id 'net.pixlies.java-conventions'
}
dependencies {
implementation 'com.github.stefvanschie.inventoryframework:IF:0.10.7'
implementation 'org.projectlombok:lombok:1.18.24'
implementation 'redis.clients:jedis:4.2.3'
implementation 'joda-time:joda-time:2.11.1'
compileOnly 'org.purpurmc.purpur:purpur-api:1.19-R0.1-SNAPSHOT'
compileOnly 'com.comphenix.protocol:ProtocolLib:4.7.0'
compileOnly 'me.clip:placeholderapi:2.11.2'
compileOnly 'net.luckperms:api:5.4'
}
description = 'PixliesCore'
I also ran ./gradlew assemble
in the mother project's directory. Here is the output:
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':PixliesCore:compileJava'.
> invalid source release: 17
Perhaps this "invalid source release" is the cause, but I do not know what it means or how to fix it. I'm using the Java 17 SDK for everything.
Oh, also, here is the original POM.xml for the mother project:
<?xml version="1.0" encoding="UTF-8"?>
<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>
<modules>
<module>PixliesCore</module>
<module>Nations</module>
<module>MiniMick</module>
<module>LobbyModule</module>
<module>PixliesFun</module>
<module>PixliesProxyCore</module>
<module>DiploMaurice</module>
<module>ProtoBusiness</module>
</modules>
<groupId>net.pixlies</groupId>
<artifactId>version-two</artifactId>
<packaging>pom</packaging>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongo-java-driver</artifactId>
<version>3.12.11</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.11.0</version>
</dependency>
<dependency>
<groupId>co.aikar</groupId>
<artifactId>acf-paper</artifactId>
<version>0.5.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.ocpsoft.prettytime</groupId>
<artifactId>prettytime</artifactId>
<version>5.0.3.Final</version>
</dependency>
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.6</version>
</dependency>
</dependencies>
<repositories>
<repository>
<id>purpur</id>
<url>https://repo.purpurmc.org/snapshots</url>
</repository>
<repository>
<id>aikar</id>
<url>https://repo.aikar.co/content/groups/aikar/</url>
</repository>
<repository>
<id>placeholderapi</id>
<url>https://repo.extendedclip.com/content/repositories/placeholderapi/</url>
</repository>
<repository>
<id>dmulloy2-repo</id>
<url>https://repo.dmulloy2.net/repository/public/</url>
</repository>
</repositories>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>16</source>
<target>16</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
And the POM.xml for the PixliesCore
subproject:
<?xml version="1.0" encoding="UTF-8"?>
<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>
<parent>
<artifactId>version-two</artifactId>
<groupId>net.pixlies</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<artifactId>PixliesCore</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<repositories>
<repository>
<id>aikar</id>
<url>https://repo.aikar.co/content/groups/aikar/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>com.github.stefvanschie.inventoryframework</groupId>
<artifactId>IF</artifactId>
<version>0.10.7</version>
</dependency>
<dependency>
<groupId>org.purpurmc.purpur</groupId>
<artifactId>purpur-api</artifactId>
<version>1.19-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.24</version>
</dependency>
<dependency>
<groupId>com.comphenix.protocol</groupId>
<artifactId>ProtocolLib</artifactId>
<version>4.7.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<version>4.3.1</version>
</dependency>
<dependency>
<groupId>me.clip</groupId>
<artifactId>placeholderapi</artifactId>
<version>2.11.2</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
<version>2.12.2</version>
</dependency>
<dependency>
<groupId>net.luckperms</groupId>
<artifactId>api</artifactId>
<version>5.4</version>
<scope>provided</scope>
</dependency>
</dependencies>
<pluginRepositories>
<pluginRepository>
<id>maven-snapshots</id>
<url>https://repository.apache.org/content/repositories/snapshots/</url>
</pluginRepository>
</pluginRepositories>
<properties>
<maven.compiler.source>16</maven.compiler.source>
<maven.compiler.target>16</maven.compiler.target>
</properties>
<build>
<defaultGoal>clean package</defaultGoal>
<finalName>PixliesCore</finalName>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.3.1-SNAPSHOT</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<dependencyReducedPomLocation>${project.build.directory}/dependency-reduced-pom.xml</dependencyReducedPomLocation>
<filters>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>META-INF/*.SF</exclude>
<exclude>META-INF/*.DSA</exclude>
<exclude>META-INF/*.RSA</exclude>
</excludes>
</filter>
</filters>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>