-2

I am trying to use gradle for the first time. What I want to do is to use ImageJ with gradle. I took the example file from imageJ website and a java code from the examples on the imageJ github. Gradle says it can't find the method compile for imageJ.

The code in gradle.build is as follow:

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'
}

The java code is contained in src/main/java and is as follow:

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);
    }

}

When I run gradle build, I receive the following error: Could not find method compile() for arguments [net.imagej:imagej

tkruse
  • 10,222
  • 7
  • 53
  • 80
Bubble
  • 63
  • 1
  • 9

1 Answers1

0

Do you know what, compile is a configuration that is usually introduced by a plugin; most likely the java plugin. Adding the java plugin on top of your build script should do the trick:

apply plugin: 'java'

So your build script looks like this:

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'
}
1218985
  • 7,531
  • 2
  • 25
  • 31