I get this error when trying to run the code that is further below.
Unnecessarily replacing a task that does not exist is not supported. Use create() or register() >directly instead. You attempted to replace a task named 'PDFCreator.main()', but there is no existing >task with that name."
Everything that comes up in the console/terminal when trying to run it (I run it by using the small green arrow and not by using "start gradlew.bat run", as i have another main method which is run that way, if it matters at all):
23:51:25: Executing task 'PDFCreator.main()'...
FAILURE: Build failed with an exception.
* Where:
Initialization script 'C:\Users\myusername\AppData\Local\Temp\PDFCreator_main__.gradle' line: 18
* What went wrong:
A problem occurred configuring root project 'blablabla'.
> Could not create task ':PDFCreator.main()'.
> Unnecessarily replacing a task that does not exist is not supported. Use create() or register() directly instead. You attempted to replace a task named 'PDFCreator.main()', but there is no existing task with that name.
* 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 7.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/6.0/userguide/command_line_interface.html#sec:command_line_warnings
BUILD FAILED in 956ms
23:51:26: Task execution finished 'PDFCreator.main()'.
The code I am trying to run:
package blablabla;
import com.itextpdf.io.image.ImageDataFactory;
import com.itextpdf.kernel.pdf.PdfDocument;
import com.itextpdf.kernel.pdf.PdfWriter;
import com.itextpdf.layout.Document;
import com.itextpdf.layout.element.Image;
import com.itextpdf.layout.element.Paragraph;
import java.io.FileNotFoundException;
import java.net.MalformedURLException;
public class PDFCreator {
public void createPDF2() throws FileNotFoundException, MalformedURLException {
PdfDocument pdf = new PdfDocument(new PdfWriter("Test.pdf"));
Document document = new Document(pdf);
Image img = new Image(ImageDataFactory.create("https://images.unsplash.com/photo-1542044896530-05d85be9b11a?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1000&q=60"));
document.add(img);
document.add(new Paragraph("Dette er en test"));
document.close();
}
public static void main(String[] args) throws FileNotFoundException, MalformedURLException {
PDFCreator klient = new PDFCreator();
System.out.println("Hei");
klient.createPDF2();
}
}
I have tried to google around a bit but haven't found any solutions that work. I have tried:
- Deleting .IDEA folder
- Deleting .gradle folder
- Restarting IntelliJ several times
- Clearing IntelliJ cache
- Restarting computer
- Git pull lots of times (The code works on my friend's computer)
- Deleting the file where the error occurs (Under the *Where: in the message from the terminal)
As I do not know what to try next, I am hoping that someone here can help me :) In advance, thank you for your help :)
SOLUTION: In IntelliJ settings - gradle - change build and run to IntelliJ and not Gradle.
