java - Gradle 找不到方法编译
问题描述
我第一次尝试使用 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
解决方案
你知道吗,compile
是一个configuration
通常由插件引入的;很可能是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'
}
推荐阅读
- python - 如何在 Jupyter Notebook 中运行 shell 脚本?
- sql-server - Azure SQL DW COPY 命令失败并出现语法错误
- python - Looking to automate seller login portal with Python and Selenium , find xPath
- cucumber - Maven Surefire 报告显示跳过的测试为通过
- python - Why calling base class contructor is mandatory?
- c - GTK keypress event propagation either causes recursion or does not work
- blazor - Why does Blazor renders component twice
- android - Prevent firebase test labs from clicking ads
- java - 获取 org.springframework.orm.jpa.JpaObjectRetrievalFailureException:无法找到具有 id 的对象
- sql - 测试 COUNT 个缺失小时并将结果显示为某种数组?