开发者社区> 问答> 正文

“不支持不必要地替换不存在的任务”-错误

当尝试运行下面的代码时,出现此错误。

不支持不必要地替换不存在的任务。直接使用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,但没有找到任何有效的解决方案。我试过了:

  1. 删除.IDEA文件夹
  2. 删除.gradle文件夹
  3. 多次重启IntelliJ
  4. 清除IntelliJ缓存
  5. 重启电脑
  6. Git拉了很多次(代码在我朋友的计算机上工作)
  7. 删除发生错误的文件(在终端消息中的* Where:下) 由于我不知道接下来要尝试什么,我希望这里有人可以帮助我:)提前,谢谢您的帮助:)

解决方案:在IntelliJ设置中-gradle-更改生成并运行到IntelliJ,而不是Gradle。

java gradle intellij-idea

问题来源:Stack Overflow

展开
收起
montos 2020-03-21 21:43:29 1999 0
1 条回答
写回答
取消 提交回答
问答分类:
问答地址:
问答排行榜
最热
最新

相关电子书

更多
面向失败设计 立即下载
JS 语言在引擎级别的执行过程 立即下载
低代码开发师(初级)实战教程 立即下载