gpt4 book ai didi

java - Gradle 找不到方法编译

转载 作者:行者123 更新时间:2023-12-03 06:33:10 24 4
gpt4 key购买 nike

这个问题在这里已经有了答案:





Could not find method compile() for a multi module project

(2 个回答)


2年前关闭。




我第一次尝试使用 gradle。我想要做的是将 ImageJ 与 gradle 一起使用。我从 imageJ 网站获取了示例文件,并从 imageJ github 上的示例中获取了 java 代码。
Gradle 说它找不到为 imageJ 编译的方法。

gradle.build 中的代码如下:

buildscript {
repositories {
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
// classpath "io.spring.gradle:dependency-management-plugin:0.5.4.RELEASE"
classpath "io.spring.gradle:dependency-management-plugin:1.0.8.RELEASE"
}
}
apply plugin: "io.spring.dependency-management"

repositories {
jcenter()
maven {
url "http://maven.imagej.net/content/groups/public/"
}
}
dependencyManagement {
imports {
mavenBom 'net.imagej:pom-imagej:14.1.0'
}
}

dependencies {
compile 'net.imagej:imagej'
}


Java 代码包含在 src/main/java 中,如下所示:
package test;

import java.io.File;

import net.imagej.Dataset;
import net.imagej.ImageJ;

/** Loads and displays a dataset using the ImageJ API. */
public class LoadAndDisplayDataset {

public static void main(final String... args) throws Exception {
// create the ImageJ application context with all available services
final ImageJ ij = new ImageJ();

// ask the user for a file to open
final File file = ij.ui().chooseFile(null, "open");

// load the dataset
final Dataset dataset = ij.scifio().datasetIO().open(file.getPath());

// display the dataset
ij.ui().show(dataset);
}

}

当我运行 gradle build ,我收到以下错误: Could not find method compile() for arguments [net.imagej:imagej

最佳答案

你知道吗,compileconfiguration通常由插件引入;很可能是java插件。在构建脚本之上添加 java 插件应该可以解决问题:

apply plugin: 'java'

因此,您的构建脚本如下所示:
apply plugin: 'java'
apply plugin: "io.spring.dependency-management"

buildscript {
repositories {
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath "io.spring.gradle:dependency-management-plugin:1.0.8.RELEASE"
}
}

repositories {
jcenter()
maven {
url "http://maven.imagej.net/content/groups/public/"
}
}

dependencyManagement {
imports {
mavenBom 'net.imagej:pom-imagej:14.1.0'
}
}

dependencies {
compile 'net.imagej:imagej'
}

关于java - Gradle 找不到方法编译,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57261861/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com