I am building a gradle java project using sublime, instead of an IDE like eclipse. I have notice when I run the build task, I do not get any warnings about unused imports.
Is there a compiler option in java that can turn on my strict warnings? If so, how do I enable that in my build.gradle?
Thanks.
Warning on unused imports is not something the Java compiler currently handles: https://docs.oracle.com/en/java/javase/14/docs/specs/man/javac.html#examples-of-using--xlint-keys
You can use an external code style tool to take care of that for you. For example, with Spotless
plugins {
`java`
id("com.diffplug.gradle.spotless") version "4.0.0"
}
spotless {
java {
eclipse()
removeUnusedImports()
trimTrailingWhitespace()
endWithNewline()
}
}
and the following Java source with unused List import:
import java.util.List;
public class Example {
public static void main(String[] args) {
System.out.println("hello");
}
}
when I try to build the project, I will immediately get an error:
> Task :build FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':buildSrc:spotlessJava'.
> The following files had format violations:
src\main\java\io\mateo\gradle\build\Example.java
## -1,7 +1,5 ##
package╖io.mateo.gradle.build;
-import╖java.util.List;
-
public╖class╖Example╖{
\tpublic╖static╖void╖main(String[]╖args)╖{
Run 'gradlew spotlessApply' to fix these violations.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
Related
I am facing the following issue while running command : 'react-native run-android' , I have tried to make changes in '/Users/ankitkumar/teachersapp_new/android/app/build/generated/rncli/src/main/java/com/facebook/react/PackageList.java' but it automatically get reset when running the command. Can anyone please help?
> Task :app:compileDebugJavaWithJavac FAILED
Deprecated Gradle features were used in this build, making it incompatible with Gradle 8.0.
You can use '--warning-mode all' to show the individual deprecation warnings and determine if they come from your own scripts or plugins.
See https://docs.gradle.org/7.3.3/userguide/command_line_interface.html#sec:command_line_warnings
665 actionable tasks: 77 executed, 588 up-to-date
Warning: unexpected element (uri:"", local:"base-extension"). Expected elements are <{}codename>,<{}layoutlib>,<{}api-level>
/Users/ankitkumar/teachersapp_new/android/app/build/generated/rncli/src/main/java/com/facebook/react/PackageList.java:63: error: a type with the same simple name is already defined by the single-type-import of OrientationPackage
import org.wonday.orientation.OrientationPackage;
^
/Users/ankitkumar/teachersapp_new/android/app/build/generated/rncli/src/main/java/com/facebook/react/PackageList.java:158: error: reference to OrientationPackage is ambiguous
new OrientationPackage(),
^
both class com.github.yamill.orientation.OrientationPackage in com.github.yamill.orientation and class org.wonday.orientation.OrientationPackage in org.wonday.orientation match
/Users/ankitkumar/teachersapp_new/android/app/build/generated/rncli/src/main/java/com/facebook/react/PackageList.java:159: error: reference to OrientationPackage is ambiguous
new OrientationPackage(),
^
both class com.github.yamill.orientation.OrientationPackage in com.github.yamill.orientation and class org.wonday.orientation.OrientationPackage in org.wonday.orientation match
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
3 errors
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:compileDebugJavaWithJavac'.
> Compilation failed; see the compiler error output for details.
* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 1m 25s
error Failed to install the app. Make sure you have the Android development environment set up: https://reactnative.dev/docs/environment-setup.
Error: Command failed: ./gradlew app:installDebug -PreactNativeDevServerPort=8081
Warning: unexpected element (uri:"", local:"base-extension"). Expected elements are <{}codename>,<{}layoutlib>,<{}api-level>
/Users/ankitkumar/teachersapp_new/android/app/build/generated/rncli/src/main/java/com/facebook/react/PackageList.java:63: error: a type with the same simple name is already defined by the single-type-import of OrientationPackage
import org.wonday.orientation.OrientationPackage;
^
/Users/ankitkumar/teachersapp_new/android/app/build/generated/rncli/src/main/java/com/facebook/react/PackageList.java:158: error: reference to OrientationPackage is ambiguous
new OrientationPackage(),
^
both class com.github.yamill.orientation.OrientationPackage in com.github.yamill.orientation and class org.wonday.orientation.OrientationPackage in org.wonday.orientation match
/Users/ankitkumar/teachersapp_new/android/app/build/generated/rncli/src/main/java/com/facebook/react/PackageList.java:159: error: reference to OrientationPackage is ambiguous
new OrientationPackage(),
^
both class com.github.yamill.orientation.OrientationPackage in com.github.yamill.orientation and class org.wonday.orientation.OrientationPackage in org.wonday.orientation match
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
3 errors
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:compileDebugJavaWithJavac'.
> Compilation failed; see the compiler error output for details.
* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 1m 25s
I have tried to make changes in '/Users/ankitkumar/teachersapp_new/android/app/build/generated/rncli/src/main/java/com/facebook/react/PackageList.java' but it automatically get reset when running the command and the build is unsuccessful.
Follow below steps and check if same issue still exist
If you did any manual linking like mentioned here then revert back all the changes
Run npx react-native unlink react-native-orientation
Run npm uninstall react-native-orientation
Delete node_modules
Delete build folders (android/build & android/app/build)
Run npm install or yarn to install packages
Check if app builds without react-native-orientation package.If yes, goto next next. If no, add the fix mentioned here React Native Android build failure with different errors without any changes in code for past days due to publish of React Native version 0.71.0-rc.0 then check if app works then, execute next step
run npm install react-native-orientation
Run npx react-native link react-native-orientation
Clean & build
I'm on windows 10, when I do "gradlew genSources" then this happened
Starting a Gradle Daemon, 7 stopped Daemons could not be reused, use --status for details
> Configure project :
Fabric Loom: 0.10.66
FAILURE: Build failed with an exception.
* Where:
Build file 'C:\Users\user\Downloads\MCJAVA\vector-addon\build.gradle'
* What went wrong:
Could not compile build file 'C:\Users\user\Downloads\MCJAVA\vector-addon\build.gradle'.
> startup failed:
General error during conversion: Unsupported class file major version 62
java.lang.IllegalArgumentException: Unsupported class file major version 62
1 error
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
Deprecated Gradle features were used in this build, making it incompatible with Gradle 8.0.
You can use '--warning-mode all' to show the individual deprecation warnings and determine if they come from your own scripts or plugins.
See https://docs.gradle.org/7.2/userguide/command_line_interface.html#sec:command_line_warnings
BUILD FAILED in 5s
I want to know how can i fix it and im not good at coding and my english is not that good, I still tried with --stacktrace it still have similir error please help me
(its have a lot more text in code but its too much and i dont think it important)
Where I try to run code in Android studio, its not working and displaying error attached below. example:
package com.example.jerry;
public class Test {
public static void main(String[] args) {
System.out.println("Hello World");
}
}
Got error when running Java class Test.class. This is the error displaying:
5:06:58 PM: Executing task 'Test.main()'...
Executing tasks: [Test.main()] in project G:\JavaProject\Jerry
FAILURE: Build failed with an exception.
* Where:
Initialization script 'C:\Users\Shakil\AppData\Local\Temp\Test_main__1.gradle' line: 21
* What went wrong:
A problem occurred configuring project ':app'.
> Could not create task ':app:Test.main()'.
> SourceSet with name 'main' not found.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 271ms
Deprecated Gradle features were used in this build, making it incompatible with Gradle 8.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/7.0.2/userguide/command_line_interface.html#sec:command_line_warnings
5:06:58 PM: Task execution finished 'Test.main()'.
When I use Scanners or try to get a user input, I get the message:
FAILURE: Build failed with an exception.
What went wrong:
Execution failed for task ':run'.
Process 'command 'C:\Program Files\Java\jdk-13.0.1\bin\java.exe'' finished with non-zero exit value 1
Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
Get more help at https://help.gradle.org
BUILD FAILED in 0s
2 actionable tasks: 1 executed, 1 up-to-date
When I just use a system.out.println();
It goes through successfully.
Here is my code:
/**
*
* #author boaz5
*/
import java.io.IOException;
import java.util.Scanner;
public class Main {
/**
* #param args the command line arguments
*/
public static void main(String[] args) throws IOException {
System.out.println("What is your name?");
Scanner name = new Scanner(System.in);
String nameString = name.next();
System.out.println("Hi," + nameString);
}
}
I'm not sure what I'm doing wrong. I am a complete newbie and this is one of my first Java projects. Thanks!
Not much to go on here, but I can give a couple suggestions to get started:
1.) Update your Gradle plug-in. The compilation issue may not be code related, but instead a problem with the tooling.
2.) If above fails replace the IOException with Exception and see if we get any further output.
Let us know
you should review your environment, I did copy your code and work for me.
12:26:02 AM: Executing task 'Test.main()'...
Task :compileJava
Task :processResources NO-SOURCE
Task :classes
Task :Test.main()
What is your name?
Alvaro
Hi,Alvaro
Deprecated Gradle features were used in this build, making it incompatible with Gradle 6.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See
There is no problem in your code. The code is running without any error.
I think you added the processor as a compile dependency. You should add it as 'provided'.
I am trying to generate the javadoc of a GWT Java project using gradle. When I run the task gradle build, the compilation is successful. However, when I run the gradle javadoc task, it fails with the following error:
C:\Users\jbraga.gradle\caches\modules-2\files-2.1\com.google.gwt\gwt-user\2.8.1\9a13fbee70848f1f1cddd3ae33ad180af3392d9e\gwt-user-2.8.1.jar(com/google/gwt/user/client/ui/Widget.java):28: error: cannot access Event
import com.google.gwt.user.client.Event;
^
bad source file: C:\Users\jbraga.gradle\caches\modules-2\files-2.1\com.google.gwt\gwt-user\2.8.1\9a13fbee70848f1f1cddd3ae33ad180af3392d9e\gwt-user-2.8.1.jar(com/google/gwt/user/client/Event.java)
file does not contain class com.google.gwt.user.client.Event
Please remove or make sure it appears in the correct subdirectory of the sourcepath.
C:\Users\jbraga.gradle\caches\modules-2\files-2.1\com.google.gwt\gwt-user\2.8.1\9a13fbee70848f1f1cddd3ae33ad180af3392d9e\gwt-user-2.8.1.jar(com/google/gwt/layout/client/Layout.java):18: error: cannot find symbol
import static com.google.gwt.dom.client.Style.Unit.PX;
^
symbol: static PX
location: class
FAILURE: Build failed with an exception.
What went wrong:
Execution failed for task ':javadoc'.
Javadoc generation failed. Generated Javadoc options file (useful for troubleshooting): 'C:\Users\jbraga\odsoft-18-19-nmb-g302\odsoft\exercise1\component1\students\build\tmp\javadoc\javadoc.options'
Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
Get more help at https://help.gradle.org
BUILD FAILED in 4s
The GWT version I am using is 2.8.1 and the same occurs with 2.8.2. The gradle.properties file specifies the correct path to the SDK.
Does anyone have a solution to this problem?
Thanks in advance.
This is a known Gradle issue: https://github.com/gradle/gradle/issues/5630, fortunately with a known workaround:
javadoc {
options.addStringOption("sourcepath", "")
}
For me, a slight modification of Thomas Broyer suggested workaround has worked:
javadoc {
options.addStringOption("sourcepath", "")
}