【问题标题】:Gradle Could not find method compile [duplicate]Gradle找不到方法编译[重复]
【发布时间】:2019-07-29 21:55:28
【问题描述】:

我是第一次尝试使用 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

【问题讨论】:

    标签: java gradle imagej


    【解决方案1】:

    你知道吗,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'
    }
    

    【讨论】:

      猜你喜欢
      • 2018-10-22
      • 2017-12-05
      • 2018-02-06
      • 1970-01-01
      • 2021-01-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多