当尝试运行下面的代码时,出现此错误。
不支持不必要地替换不存在的任务。直接使用create()或register()>。您试图替换名为'PDFCreator.main()'的任务,但是该名称不存在> task。” 尝试运行控制台/终端时出现在控制台/终端中的所有内容(我通过使用绿色的小箭头而不是通过使用“ start gradlew.bat run”来运行它,因为我有另一种以这种方式运行的主要方法很重要):
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()'.
我正在尝试运行的代码:
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();
}
}
我曾尝试过搜索一下Google,但没有找到任何有效的解决方案。我试过了:
解决方案:在IntelliJ设置中-gradle-更改生成并运行到IntelliJ,而不是Gradle。
java gradle intellij-idea
问题来源:Stack Overflow
我建议更新到最新的IntelliJ IDEA版本。如果仍不能解决问题,请尝试使用Gradle 5。
解决方法是不要将构建/运行委托给Gradle,而应使用IntelliJ IDEA。
回答来源:Stack Overflow
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。