Beispiel #1
0
  @TaskAction
  public void runApp() {

    final Project project = getProject();
    final SourceSet main = ComputeMain.findMainSourceSet(project);
    final File outputDir = (main == null ? null : main.getOutput().getResourcesDir());
    final Set<File> allResources = new LinkedHashSet<File>();
    if (main != null) {
      allResources.addAll(main.getResources().getSrcDirs());
    }

    project
        .getTasks()
        .withType(
            JavaExec.class,
            new Action<JavaExec>() {

              @Override
              public void execute(JavaExec exec) {
                ArrayList<File> files = new ArrayList<File>(exec.getClasspath().getFiles());
                files.addAll(0, allResources);
                getLogger().info("Adding classpath: " + allResources);
                exec.setClasspath(new SimpleFileCollection(files));
                if (exec.getMain() == null) {
                  final String mainClass = findMainClass(main);
                  exec.setMain(mainClass);
                  exec.getConventionMapping()
                      .map(
                          "main",
                          new Callable<String>() {

                            @Override
                            public String call() throws Exception {
                              return mainClass;
                            }
                          });
                  getLogger().info("Found main: " + mainClass);
                }
                if (outputDir != null) {
                  for (File directory : allResources) {
                    FileUtils.removeDuplicatesFromOutputDirectory(outputDir, directory);
                  }
                }
                exec.exec();
              }
            });
  }
  private void definePathsForSourceSet(
      final SourceSet sourceSet, ConventionMapping outputConventionMapping, final Project project) {
    outputConventionMapping.map(
        "classesDir",
        new Callable<Object>() {
          public Object call() throws Exception {
            String classesDirName = String.format("classes/%s", sourceSet.getName());
            return new File(project.getBuildDir(), classesDirName);
          }
        });
    outputConventionMapping.map(
        "resourcesDir",
        new Callable<Object>() {
          public Object call() throws Exception {
            String classesDirName = String.format("resources/%s", sourceSet.getName());
            return new File(project.getBuildDir(), classesDirName);
          }
        });

    sourceSet.getJava().srcDir(String.format("src/%s/java", sourceSet.getName()));
    sourceSet.getResources().srcDir(String.format("src/%s/resources", sourceSet.getName()));
  }
Beispiel #3
0
  private File _getResourcesDir(Project project) {
    SourceSet sourceSet = GradleUtil.getSourceSet(project, SourceSet.MAIN_SOURCE_SET_NAME);

    return _getSrcDir(sourceSet.getResources());
  }