Search code examples
javagradleappletdeprecated

Gradle 7.4 fails with Applet been deprecated and marked for removal


Eclipse is hanging on me, so I reverted to a gradle build. Gradle classes fails with the error message below.

I do have a gradle.properties file in the project directory with: "org.gradle.warning.mode=none" in it. Eclipse normally runs the code and tests just fine.

I don't care about getting the warnings anywhere. I do want to stop the build from failing.

The build file below has a lot of extra stuff that I am not using now.

Edit 1: adding @SuppressWarnings("removal") seems to work.

C:\Users\raz\git\code\src\simplegui\InsetsDemo.java:4: warning: [removal] Applet in java.appl
et has been deprecated and marked for removal
public class InsetsDemo extends Applet {
                                ^
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.

build file:

buildscript {
  repositories {
    mavenCentral()
  }
  dependencies {
    classpath 'org.hidetake:gradle-ssh-plugin:1.1.2'
  }
}
plugins {
    id 'java'
    id 'checkstyle'
    id 'distribution'
    id 'application'
}
repositories {
    mavenCentral()
}
sourceSets {
    main {
        main.java.srcDirs = ["src"]
        main.resources.srcDirs = ["resources"]
    }
    test {
        test.java.srcDirs = ["tst"] // removed slow/ as it was very.
    }
}
dependencies {
    testImplementation 'junit:junit:4.13.2'
    }
jar {
    manifest {
        attributes 'Main-Class': MyStuff.main
    }
}
run {
    standardInput = System.in
}
targetCompatibility = "16"  
sourceCompatibility = "16"
version = '0.1' 
mainClassName = MyStuff.main // for application plugin
class MyStuff {
    public static final String main="com.tayek.utilities.Dispatcher";
}

Solution

  • Is your build really failing because of that deprecation warning? As Oliver noted in the comments, that should only be the case when you run javac with the -Werror option. But even if you used that option, then the message would look different – probably like this:

    error: warnings found and -Werror specified
    1 error
    1 warning
    

    So from what I can tell, it rather seems that this deprecation warning is a red herring. Just to make sure: does your build fail at all? When you run ./gradlew classes, does Gradle report something like the following …

    > Compilation failed; see the compiler error output for details.
    

    … followed by “BUILD FAILED”?

    If Gradle instead reports “BUILD SUCCESSFUL” for that command, then the warning is not an issue. If your build still fails when running other tasks (e.g., as part of ./gradlew build), then there should be other errors in the log. If not, then try adding the --stacktrace option to hopefully get more details about the actual error.


    That said, if you only want to (entirely) get rid of that warning, then according to this SO answer your only option would be to add a @SuppressWarnings("deprecation") annotation to your InsetsDemo class. Otherwise the warning was “mandated by the Java Language Specification.”