org.gradle.api.plugins.JavaPlugin Java Examples

The following examples show how to use org.gradle.api.plugins.JavaPlugin. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source Project: gradle-plugins   Author: freefair   File: SourcesJarPlugin.java    License: MIT License 7 votes vote down vote up
@Override
public void apply(Project project) {

    project.getLogger().warn("io.freefair.sources-jar is deprecated. Use java.withSourcesJar() instead");

    project.getPluginManager().withPlugin("java", appliedPlugin -> {
        sourcesJar = project.getTasks().register("sourcesJar", Jar.class, sourcesJar -> {
            sourcesJar.setDescription("Assembles a jar archive containing the sources.");
            sourcesJar.getArchiveClassifier().set("sources");
            sourcesJar.setGroup(BasePlugin.BUILD_GROUP);

            sourcesJar.dependsOn(project.getTasks().named(JavaPlugin.CLASSES_TASK_NAME));

            JavaPluginConvention javaPluginConvention = project.getConvention().getPlugin(JavaPluginConvention.class);
            DefaultSourceSet mainSourceSet = (DefaultSourceSet) javaPluginConvention.getSourceSets().getByName(SourceSet.MAIN_SOURCE_SET_NAME);
            sourcesJar.from(mainSourceSet.getAllSource());
        });

        project.getArtifacts().add(Dependency.ARCHIVES_CONFIGURATION, sourcesJar);
    });
}
 
Example #2
Source Project: gradle-plugins   Author: freefair   File: AspectJPlugin.java    License: MIT License 7 votes vote down vote up
@Override
public void apply(Project project) {
    this.project = project;
    project.getPlugins().apply(AspectJBasePlugin.class);
    project.getPlugins().apply(JavaBasePlugin.class);

    JavaPluginConvention plugin = project.getConvention().getPlugin(JavaPluginConvention.class);

    plugin.getSourceSets().all(this::configureSourceSet);

    project.getPlugins().withType(JavaPlugin.class, javaPlugin -> {

        SourceSet main = plugin.getSourceSets().getByName(SourceSet.MAIN_SOURCE_SET_NAME);
        SourceSet test = plugin.getSourceSets().getByName(SourceSet.TEST_SOURCE_SET_NAME);

        DefaultAspectjSourceSet mainAj = new DslObject(main).getConvention().getPlugin(DefaultAspectjSourceSet.class);
        DefaultAspectjSourceSet testAj = new DslObject(test).getConvention().getPlugin(DefaultAspectjSourceSet.class);

        Configuration aspectpath = project.getConfigurations().getByName(mainAj.getAspectConfigurationName());
        Configuration testAspectpath = project.getConfigurations().getByName(testAj.getAspectConfigurationName());

        testAspectpath.extendsFrom(aspectpath);

        testAj.setAspectPath(project.getObjects().fileCollection().from(main.getOutput(), testAspectpath));
    });
}
 
Example #3
Source Project: gradle-java-modules   Author: gradle   File: JigsawPlugin.java    License: Apache License 2.0 7 votes vote down vote up
private void configureCompileTestJavaTask(final Project project) {
    final JavaCompile compileTestJava = (JavaCompile) project.getTasks()
            .findByName(JavaPlugin.COMPILE_TEST_JAVA_TASK_NAME);
    final SourceSet test = ((SourceSetContainer) project.getProperties().get("sourceSets")).getByName("test");
    final JavaModule module = (JavaModule) project.getExtensions().getByName(EXTENSION_NAME);
    compileTestJava.getInputs().property("moduleName", module.geName());
    compileTestJava.doFirst(new Action<Task>() {
        @Override
        public void execute(Task task) {
            List<String> args = new ArrayList<>();
            args.add("--module-path");
            args.add(compileTestJava.getClasspath().getAsPath());
            args.add("--add-modules");
            args.add("junit");
            args.add("--add-reads");
            args.add(module.geName() + "=junit");
            args.add("--patch-module");
            args.add(module.geName() + "=" + test.getJava().getSourceDirectories().getAsPath());
            compileTestJava.getOptions().setCompilerArgs(args);
            compileTestJava.setClasspath(project.files());
        }
    });
}
 
Example #4
Source Project: gradle-modules-plugin   Author: java9-modularity   File: CompileModuleInfoTask.java    License: MIT License 6 votes vote down vote up
/**
 * Preconfigures a separate task that is meant to compile {@code module-info.java} separately.
 * Final (modular) configuration is performed later by {@link CompileJavaTaskMutator}.
 */
private JavaCompile preconfigureCompileModuleInfoJava(JavaCompile compileJava) {
    var compileModuleInfoJava = helper().compileJavaTask(CompileModuleOptions.COMPILE_MODULE_INFO_TASK_NAME);

    compileModuleInfoJava.setClasspath(project.files()); // empty
    compileModuleInfoJava.setSource(pathToModuleInfoJava());
    compileModuleInfoJava.getOptions().setSourcepath(project.files(pathToModuleInfoJava().getParent()));

    compileModuleInfoJava.setDestinationDir(helper().getModuleInfoDir());

    // we need all the compiled classes before compiling module-info.java
    compileModuleInfoJava.dependsOn(compileJava);

    // make "classes" trigger module-info.java compilation
    helper().task(JavaPlugin.CLASSES_TASK_NAME).dependsOn(compileModuleInfoJava);

    return compileModuleInfoJava;
}
 
Example #5
Source Project: gradle-modules-plugin   Author: java9-modularity   File: MergeClassesTask.java    License: MIT License 6 votes vote down vote up
public void configureMergeClassesAfterEvaluate() {
    if (!mergeClassesHelper().isMergeRequired()) {
        return;
    }

    var mergeClasses = mergeClassesHelper().createMergeClassesTask();

    mergeClassesHelper().allCompileTaskStream().forEach(task -> {
        mergeClasses.from(task.getDestinationDir());
        mergeClasses.dependsOn(task);
    });
    mergeClasses.into(helper().getMergedDir());

    Stream.of(ApplicationPlugin.TASK_RUN_NAME, JavaPlugin.TEST_TASK_NAME)
            .map(helper()::findTask)
            .flatMap(Optional::stream)
            .forEach(task -> task.dependsOn(mergeClasses));
}
 
Example #6
Source Project: gradle-plugins   Author: freefair   File: JSassJavaPlugin.java    License: MIT License 6 votes vote down vote up
@Override
public void apply(Project project) {
    project.getPlugins().apply(JSassWebjarsPlugin.class);

    project.getPlugins().apply(JavaPlugin.class);

    File baseDestinationDir = new File(project.getBuildDir(), "jsass");

    project.getConvention().getPlugin(JavaPluginConvention.class).getSourceSets().all(sourceSet -> {
        String taskName = sourceSet.getCompileTaskName("Sass");

        TaskProvider<SassCompile> sassCompileTaskProvider = project.getTasks().register(taskName, SassCompile.class, sassCompile -> {
            sassCompile.setSource(sourceSet.getResources());
            sassCompile.getDestinationDir().set(new File(baseDestinationDir, sourceSet.getName()));
            sassCompile.setGroup(BasePlugin.BUILD_GROUP);
            sassCompile.setDescription("Compile sass and scss files for the " + sourceSet.getName() + " source set");
        });

        project.getTasks().named(sourceSet.getProcessResourcesTaskName(), ProcessResources.class)
                .configure(processResources -> processResources.from(sassCompileTaskProvider));
    });
}
 
Example #7
Source Project: quarkus   Author: quarkusio   File: QuarkusDev.java    License: Apache License 2.0 6 votes vote down vote up
private void addSelfWithLocalDeps(Project project, DevModeContext context, Set<String> visited,
        Set<AppArtifactKey> addedDeps, boolean root) {
    if (!visited.add(project.getPath())) {
        return;
    }
    final Configuration compileCp = project.getConfigurations().findByName(JavaPlugin.COMPILE_CLASSPATH_CONFIGURATION_NAME);
    if (compileCp != null) {
        compileCp.getIncoming().getDependencies().forEach(d -> {
            if (d instanceof ProjectDependency) {
                addSelfWithLocalDeps(((ProjectDependency) d).getDependencyProject(), context, visited, addedDeps, false);
            }
        });
    }

    addLocalProject(project, context, addedDeps, root);
}
 
Example #8
Source Project: gradle-plugins   Author: freefair   File: WarAttachClassesPlugin.java    License: MIT License 6 votes vote down vote up
@Override
public void apply(Project project) {
    project.getPlugins().apply(WarPlugin.class);

    WarAttachClassesConvention attachClassesConvention = new WarAttachClassesConvention();

    project.getTasks().named(WarPlugin.WAR_TASK_NAME, War.class, war ->
            war.getConvention().getPlugins().put("attachClasses", attachClassesConvention)
    );

    project.afterEvaluate(p -> {
        if (attachClassesConvention.isAttachClasses()) {
            TaskProvider<Jar> jar = project.getTasks().named(JavaPlugin.JAR_TASK_NAME, Jar.class, j ->
                    j.getArchiveClassifier().convention(attachClassesConvention.getClassesClassifier())
            );

            project.getArtifacts().add(Dependency.ARCHIVES_CONFIGURATION, jar);
        }
    });
}
 
Example #9
Source Project: curiostack   Author: curioswitch   File: CuriostackRootPlugin.java    License: MIT License 6 votes vote down vote up
private static void addStandardJavaTestDependencies(Project project) {
  DependencyHandler dependencies = project.getDependencies();

  dependencies.add(JavaPlugin.COMPILE_ONLY_CONFIGURATION_NAME, "com.google.code.findbugs:jsr305");
  dependencies.add(
      JavaPlugin.TEST_IMPLEMENTATION_CONFIGURATION_NAME,
      "org.curioswitch.curiostack:curio-testing-framework");
  dependencies.add(JavaPlugin.TEST_IMPLEMENTATION_CONFIGURATION_NAME, "org.assertj:assertj-core");
  dependencies.add(
      JavaPlugin.TEST_IMPLEMENTATION_CONFIGURATION_NAME, "org.awaitility:awaitility");
  dependencies.add(JavaPlugin.TEST_IMPLEMENTATION_CONFIGURATION_NAME, "junit:junit");
  dependencies.add(JavaPlugin.TEST_IMPLEMENTATION_CONFIGURATION_NAME, "org.mockito:mockito-core");
  dependencies.add(
      JavaPlugin.TEST_IMPLEMENTATION_CONFIGURATION_NAME, "org.mockito:mockito-junit-jupiter");
  dependencies.add(
      JavaPlugin.TEST_IMPLEMENTATION_CONFIGURATION_NAME, "info.solidsoft.mockito:mockito-java8");

  dependencies.add(
      JavaPlugin.TEST_IMPLEMENTATION_CONFIGURATION_NAME, "org.junit.jupiter:junit-jupiter-api");
  dependencies.add(
      JavaPlugin.TEST_RUNTIME_ONLY_CONFIGURATION_NAME, "org.junit.jupiter:junit-jupiter-engine");
  dependencies.add(
      JavaPlugin.TEST_RUNTIME_ONLY_CONFIGURATION_NAME, "org.junit.vintage:junit-vintage-engine");
}
 
Example #10
Source Project: gradle-cpd-plugin   Author: aaschmid   File: CpdPluginTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
void CpdPlugin_shouldSetCpdCheckSourceEqualsToMainAndTestSourceSetsIfJavaPluginIsApplied(Project project, TaskProvider<Cpd> cpd) {
    // Given:
    String mainFile = "src/main/java/Clazz.java";
    String testFile = "src/test/java/ClazzTest.java";

    // When:
    project.getPlugins().apply(JavaPlugin.class);
    createProjectFiles(project, mainFile, "src/resources/java/message.properties", testFile);

    project.getConvention().getPlugin(JavaPluginConvention.class).getSourceSets().getByName(SourceSet.MAIN_SOURCE_SET_NAME, sourceSet -> {
        sourceSet.getJava().srcDir(testFile(JAVA, "de/aaschmid/annotation"));
        sourceSet.getAllJava().srcDir(testFile(JAVA, "de/aaschmid/clazz"));
        sourceSet.getResources().srcDir(testFile(JAVA, "de/aaschmid/foo"));
    });
    project.getConvention().getPlugin(JavaPluginConvention.class).getSourceSets().getByName(SourceSet.TEST_SOURCE_SET_NAME, sourceSet ->
            sourceSet.getJava().srcDir(testFile(JAVA, "de/aaschmid/test")));

    // Then:
    List<File> expected = testFilesRecurseIn(JAVA, "de/aaschmid/annotation", "de/aaschmid/clazz", "de/aaschmid/test");
    expected.add(project.file(mainFile));
    expected.add(project.file(testFile));

    assertThat(cpd.get().getSource()).containsExactlyInAnyOrderElementsOf(expected);
}
 
Example #11
Source Project: gradle-plugins   Author: freefair   File: SourcesJarPlugin.java    License: MIT License 6 votes vote down vote up
@Override
public void apply(Project project) {

    project.getLogger().warn("io.freefair.sources-jar is deprecated. Use java.withSourcesJar() instead");

    project.getPluginManager().withPlugin("java", appliedPlugin -> {
        sourcesJar = project.getTasks().register("sourcesJar", Jar.class, sourcesJar -> {
            sourcesJar.setDescription("Assembles a jar archive containing the sources.");
            sourcesJar.getArchiveClassifier().set("sources");
            sourcesJar.setGroup(BasePlugin.BUILD_GROUP);

            sourcesJar.dependsOn(project.getTasks().named(JavaPlugin.CLASSES_TASK_NAME));

            JavaPluginConvention javaPluginConvention = project.getConvention().getPlugin(JavaPluginConvention.class);
            DefaultSourceSet mainSourceSet = (DefaultSourceSet) javaPluginConvention.getSourceSets().getByName(SourceSet.MAIN_SOURCE_SET_NAME);
            sourcesJar.from(mainSourceSet.getAllSource());
        });

        project.getArtifacts().add(Dependency.ARCHIVES_CONFIGURATION, sourcesJar);
    });
}
 
Example #12
Source Project: gradle-plugins   Author: freefair   File: JSassWebjarsPlugin.java    License: MIT License 6 votes vote down vote up
@Override
public void apply(Project project) {
    project.getPlugins().apply(JSassBasePlugin.class);
    Configuration webjars = project.getConfigurations().create("webjars");

    project.getPlugins().withType(JavaPlugin.class, javaPlugin ->
            webjars.extendsFrom(project.getConfigurations().getByName(JavaPlugin.COMPILE_CLASSPATH_CONFIGURATION_NAME))
    );

    TaskProvider<PrepareWebjars> prepareWebjarsTaskProvider = project.getTasks().register("prepareWebjars", PrepareWebjars.class, prepareWebjars -> {
        prepareWebjars.getWebjars().from(webjars);
        prepareWebjars.getOutputDirectory().set(project.getLayout().getBuildDirectory().dir("jsass/webjars"));
    });

    project.getTasks().withType(SassCompile.class)
            .configureEach(sassCompile -> sassCompile.getIncludePaths().from(prepareWebjarsTaskProvider));
}
 
Example #13
Source Project: gradle-plugins   Author: freefair   File: AbstractGeneratorTask.java    License: MIT License 6 votes vote down vote up
@Nonnull
private List<ComponentDependency> getRuntimeDependencies() {
    return getProject().getConfigurations().getByName(JavaPlugin.RUNTIME_CLASSPATH_CONFIGURATION_NAME)
            .getResolvedConfiguration()
            .getResolvedArtifacts()
            .stream()
            .map(resolvedDependency -> {
                ComponentDependency componentDependency = new ComponentDependency();

                componentDependency.setArtifactId(resolvedDependency.getModuleVersion().getId().getName());
                componentDependency.setGroupId(resolvedDependency.getModuleVersion().getId().getGroup());
                componentDependency.setVersion(resolvedDependency.getModuleVersion().getId().getVersion());
                componentDependency.setType(resolvedDependency.getType());

                return componentDependency;
            })
            .collect(Collectors.toList());
}
 
Example #14
Source Project: gradle-plugins   Author: freefair   File: JSassJavaPlugin.java    License: MIT License 6 votes vote down vote up
@Override
public void apply(Project project) {
    project.getPlugins().apply(JSassWebjarsPlugin.class);

    project.getPlugins().apply(JavaPlugin.class);

    File baseDestinationDir = new File(project.getBuildDir(), "jsass");

    project.getConvention().getPlugin(JavaPluginConvention.class).getSourceSets().all(sourceSet -> {
        String taskName = sourceSet.getCompileTaskName("Sass");

        TaskProvider<SassCompile> sassCompileTaskProvider = project.getTasks().register(taskName, SassCompile.class, sassCompile -> {
            sassCompile.setSource(sourceSet.getResources());
            sassCompile.getDestinationDir().set(new File(baseDestinationDir, sourceSet.getName()));
            sassCompile.setGroup(BasePlugin.BUILD_GROUP);
            sassCompile.setDescription("Compile sass and scss files for the " + sourceSet.getName() + " source set");
        });

        project.getTasks().named(sourceSet.getProcessResourcesTaskName(), ProcessResources.class)
                .configure(processResources -> processResources.from(sassCompileTaskProvider));
    });
}
 
Example #15
Source Project: app-gradle-plugin   Author: GoogleCloudPlatform   File: AppEngineStandardExtensionTest.java    License: Apache License 2.0 6 votes vote down vote up
private Project setUpTestProject(String buildFileName) throws IOException {
  Path buildFile = testProjectDir.getRoot().toPath().resolve("build.gradle");
  InputStream buildFileContent =
      getClass()
          .getClassLoader()
          .getResourceAsStream(
              "projects/AppEnginePluginTest/Extension/" + buildFileName + ".gradle");
  Files.copy(buildFileContent, buildFile);

  Path webInf = testProjectDir.getRoot().toPath().resolve("src/main/webapp/WEB-INF");
  Files.createDirectories(webInf);
  File appengineWebXml = Files.createFile(webInf.resolve("appengine-web.xml")).toFile();
  Files.write(appengineWebXml.toPath(), "<appengine-web-app/>".getBytes(Charsets.UTF_8));

  Project p = ProjectBuilder.builder().withProjectDir(testProjectDir.getRoot()).build();
  p.getPluginManager().apply(JavaPlugin.class);
  p.getPluginManager().apply(WarPlugin.class);
  p.getPluginManager().apply(AppEngineStandardPlugin.class);
  ((ProjectInternal) p).evaluate();

  return p;
}
 
Example #16
Source Project: putnami-gradle-plugin   Author: Putnami   File: CodeServerBuilder.java    License: GNU Lesser General Public License v3.0 6 votes vote down vote up
private Collection<File> listProjectDepsSrcDirs(Project project) {
	ConfigurationContainer configs = project.getConfigurations();
	Configuration compileConf = configs.getByName(JavaPlugin.COMPILE_CLASSPATH_CONFIGURATION_NAME);
	DependencySet depSet = compileConf.getAllDependencies();

	List<File> result = Lists.newArrayList();
	for (Dependency dep : depSet) {
		if (dep instanceof ProjectDependency) {
			Project projectDependency = ((ProjectDependency) dep).getDependencyProject();
			if (projectDependency.getPlugins().hasPlugin(PwtLibPlugin.class)) {
				JavaPluginConvention javaConvention = projectDependency.getConvention().getPlugin(JavaPluginConvention.class);
				SourceSet mainSourceSet = javaConvention.getSourceSets().getByName(SourceSet.MAIN_SOURCE_SET_NAME);

				result.addAll(mainSourceSet.getAllSource().getSrcDirs());
			}
		}
	}
	return result;
}
 
Example #17
Source Project: app-gradle-plugin   Author: GoogleCloudPlatform   File: MultiModuleTestProject.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Build and evaluate multi-module project.
 *
 * @return root project
 */
public Project build() throws IOException {
  Project rootProject = ProjectBuilder.builder().withProjectDir(projectRoot).build();
  for (String module : modules) {
    Project p = ProjectBuilder.builder().withName(module).withParent(rootProject).build();

    // Create an appengine-web.xml for each module
    Path webInf = p.getProjectDir().toPath().resolve("src/main/webapp/WEB-INF");
    Files.createDirectories(webInf);
    File appengineWebXml = Files.createFile(webInf.resolve("appengine-web.xml")).toFile();
    Files.write(appengineWebXml.toPath(), "<appengine-web-app/>".getBytes(Charsets.UTF_8));

    p.getPluginManager().apply(JavaPlugin.class);
    p.getPluginManager().apply(WarPlugin.class);
    p.getPluginManager().apply(AppEngineStandardPlugin.class);

    DeployExtension deploy =
        p.getExtensions().getByType(AppEngineStandardExtension.class).getDeploy();
    deploy.setProjectId("project");
    deploy.setVersion("version");
  }
  ((ProjectInternal) rootProject).evaluate();
  return rootProject;
}
 
Example #18
Source Project: thorntail   Author: thorntail   File: ThorntailUtils.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Returns the most suitable Archive-Task for wrapping in the swarm jar - in the following order:
 * <p>
 * 1. Custom-JAR-Task defined in ThorntailExtension 'archiveTask'
 * 2. WAR-Task
 * 3. JAR-Task
 */
public static Jar getArchiveTask(Project project) {

    TaskCollection<Jar> existingArchiveTasks = project.getTasks().withType(Jar.class);
    Jar customArchiveTask = project.getExtensions().getByType(ThorntailExtension.class).getArchiveTask();

    if (customArchiveTask != null) {
        return existingArchiveTasks.getByName(customArchiveTask.getName());

    } else if (existingArchiveTasks.findByName(WarPlugin.WAR_TASK_NAME) != null) {
        return existingArchiveTasks.getByName(WarPlugin.WAR_TASK_NAME);

    } else if (existingArchiveTasks.findByName(JavaPlugin.JAR_TASK_NAME) != null) {
        return existingArchiveTasks.getByName(JavaPlugin.JAR_TASK_NAME);
    }

    throw new GradleException("Unable to detect Archive-Task: project contains neither 'war' nor 'jar', " +
            "nor is custom Archive-Task specified in the \"thorntail\" extension.");
}
 
Example #19
Source Project: gradle-plugins   Author: freefair   File: LombokPlugin.java    License: MIT License 6 votes vote down vote up
@Override
public void apply(Project project) {
    this.project = project;

    lombokBasePlugin = project.getPlugins().apply(LombokBasePlugin.class);
    lombokBasePlugin.getLombokExtension().getConfig().put("config.stopBubbling", "true");

    generateLombokConfig = project.getTasks().register("generateLombokConfig", GenerateLombokConfig.class, genConfig -> {
        genConfig.getProperties().convention(lombokBasePlugin.getLombokExtension().getConfig());
        genConfig.setGroup("lombok");
    });

    project.getTasks().withType(Delombok.class).configureEach(this::configureDelombokDefaults);

    project.getPlugins().withType(JavaPlugin.class, javaPlugin -> configureJavaPluginDefaults());

}
 
Example #20
Source Project: client-gradle-plugin   Author: gluonhq   File: ClientNativeBase.java    License: BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Inject
public ClientNativeBase(Project project) {
    this.project = project;
    project.getPluginManager().withPlugin("java", e ->
            dependsOn(project.getTasks().findByName(JavaPlugin.CLASSES_TASK_NAME),
                      project.getTasks().findByName(JavaPlugin.PROCESS_RESOURCES_TASK_NAME)));
}
 
Example #21
Source Project: gradle-plugins   Author: freefair   File: JavadocJarPlugin.java    License: MIT License 5 votes vote down vote up
@Override
public void apply(Project project) {
    project.getPlugins().withType(JavaPlugin.class, javaPlugin -> {

        project.getLogger().warn("io.freefair.javadoc-jar is deprecated. Use java.withJavadocJar() instead");

        javadocJar = project.getTasks().register("javadocJar", Jar.class, javadocJar -> {
            javadocJar.from(project.getTasks().named(JavaPlugin.JAVADOC_TASK_NAME));
            javadocJar.getArchiveClassifier().set("javadoc");
            javadocJar.setDescription("Assembles a jar archive containing the javadocs.");
            javadocJar.setGroup(BasePlugin.BUILD_GROUP);
        });

        project.getArtifacts().add(Dependency.ARCHIVES_CONFIGURATION, javadocJar);
    });

    project.getPlugins().withType(AggregateJavadocPlugin.class, aggregateJavadocPlugin -> {
        aggregateJavadocJar = project.getTasks().register("aggregateJavadocJar", Jar.class, aggregateJavadocJar -> {
            aggregateJavadocJar.from(aggregateJavadocPlugin.getAggregateJavadoc());
            aggregateJavadocJar.getArchiveClassifier().set("javadoc");
            aggregateJavadocJar.setGroup(BasePlugin.BUILD_GROUP);
        });

        project.getPlugins().apply(BasePlugin.class);
        project.getArtifacts().add(Dependency.ARCHIVES_CONFIGURATION, aggregateJavadocJar);

        project.getPlugins().withType(JavaPlugin.class, javaPlugin -> {
            aggregateJavadocJar.configure(aggregateJavadocJar -> {

                aggregateJavadocJar.getArchiveClassifier().convention("aggregateJavadoc");
                aggregateJavadocJar.getDestinationDirectory().set(new File(
                        project.getConvention().getPlugin(JavaPluginConvention.class).getDocsDir(),
                        "aggregateJavadoc"
                ));
            });
        });

    });
}
 
Example #22
Source Project: gradle-plugins   Author: freefair   File: JavadocUtf8PluginTest.java    License: MIT License 5 votes vote down vote up
@Test
public void apply() {
    project.getPlugins().apply(JavaPlugin.class);
    project.getPlugins().apply(JavadocUtf8Plugin.class);

    Javadoc javadoc = (Javadoc) project.getTasks().getByName(JavaPlugin.JAVADOC_TASK_NAME);
    StandardJavadocDocletOptions options = (StandardJavadocDocletOptions) javadoc.getOptions();

    assertThat(options.getDocEncoding()).isEqualToIgnoringCase("UTF-8");
    assertThat(options.getEncoding()).isEqualToIgnoringCase("UTF-8");
    assertThat(options.getCharSet()).isEqualToIgnoringCase("UTF-8");
}
 
Example #23
Source Project: gradle-modules-plugin   Author: java9-modularity   File: CompileTask.java    License: MIT License 5 votes vote down vote up
private void enforceJarForCompilation() {
    Configuration config = project.getConfigurations().getByName(JavaPlugin.COMPILE_CLASSPATH_CONFIGURATION_NAME);
    config.attributes(new Action<AttributeContainer>() {
        @Override
        public void execute(AttributeContainer attributeContainer) {
            if(GradleVersion.current().compareTo(GradleVersion.version("5.6")) < 0) {
                LOGGER.warn("Cannot enforce using JARs for compilation. Please upgrade to Gradle 5.6 or newer.");
                return;
            }
            attributeContainer.attribute(
                    LibraryElements.LIBRARY_ELEMENTS_ATTRIBUTE,
                    project.getObjects().named(LibraryElements.class, LibraryElements.JAR));
        }
    });
}
 
Example #24
Source Project: gradle-modules-plugin   Author: java9-modularity   File: DefaultModularityExtension.java    License: MIT License 5 votes vote down vote up
@Override
public void mixedJavaRelease(int mainJavaRelease, int moduleInfoJavaRelease) {
    validateMixedJavaReleaseArgs(mainJavaRelease, moduleInfoJavaRelease);

    CompileModuleOptions moduleOptions = helper().compileJavaTask(JavaPlugin.COMPILE_JAVA_TASK_NAME)
            .getExtensions().getByType(CompileModuleOptions.class);
    moduleOptions.setCompileModuleInfoSeparately(true);

    project.afterEvaluate(p -> configureMixedJavaRelease(mainJavaRelease, moduleInfoJavaRelease));
}
 
Example #25
Source Project: gradle-modules-plugin   Author: java9-modularity   File: DefaultModularityExtension.java    License: MIT License 5 votes vote down vote up
private void configureMixedJavaRelease(int mainJavaRelease, int moduleInfoJavaRelease) {
    var compileJava = helper().compileJavaTask(JavaPlugin.COMPILE_JAVA_TASK_NAME);
    setJavaRelease(compileJava, mainJavaRelease);

    var compileModuleInfoJava = helper().compileJavaTask(CompileModuleOptions.COMPILE_MODULE_INFO_TASK_NAME);
    setJavaRelease(compileModuleInfoJava, moduleInfoJavaRelease);
}
 
Example #26
Source Project: gradle-modules-plugin   Author: java9-modularity   File: CompileJavaTaskMutatorTest.java    License: MIT License 5 votes vote down vote up
@Test
void modularizeJavaCompileTask() {
    // given
    Project project = ProjectBuilder.builder().withProjectDir(new File("test-project/")).build();
    project.getPlugins().apply("java");
    JavaCompile compileJava = (JavaCompile) project.getTasks().getByName(JavaPlugin.COMPILE_JAVA_TASK_NAME);

    FileCollection classpath = project.files("dummy dir"); // we need anything on classpath
    compileJava.setClasspath(classpath);

    CompileModuleOptions moduleOptions = compileJava.getExtensions()
            .create("moduleOptions", CompileModuleOptions.class, project);
    project.getExtensions().add("moduleName", getClass().getName());
    project.getExtensions().create("patchModules", PatchModuleExtension.class);
    project.getExtensions().create("modularity", DefaultModularityExtension.class, project);

    CompileJavaTaskMutator mutator = new CompileJavaTaskMutator(project, compileJava.getClasspath(), moduleOptions);

    // when
    mutator.modularizeJavaCompileTask(compileJava);

    // then
    List<String> twoLastArguments = twoLastCompilerArgs(compileJava);
    assertEquals(
            Arrays.asList("--module-path", classpath.getAsPath()),
            twoLastArguments,
            "Two last arguments should be setting module path to the current compileJava task classpath");
}
 
Example #27
Source Project: web3j-gradle-plugin   Author: web3j   File: Web3jPlugin.java    License: Apache License 2.0 5 votes vote down vote up
public void apply(final Project target) {
    target.getPluginManager().apply(JavaPlugin.class);
    target.getPluginManager().apply(SolidityPlugin.class);
    target.getExtensions().create(Web3jExtension.NAME, Web3jExtension.class, target);
    target.getDependencies().add("implementation", "org.web3j:core:" + getProjectVersion());

    final SourceSetContainer sourceSets =
            target.getConvention().getPlugin(JavaPluginConvention.class).getSourceSets();

    target.afterEvaluate(p -> sourceSets.all(sourceSet -> configure(target, sourceSet)));
}
 
Example #28
Source Project: pushfish-android   Author: PushFish   File: EarPlugin.java    License: BSD 2-Clause "Simplified" License 5 votes vote down vote up
private void configureWithNoJavaPluginApplied(final Project project, final EarPluginConvention earPluginConvention) {
    project.getTasks().withType(Ear.class, new Action<Ear>() {
        public void execute(final Ear task) {
            task.from(new Callable<FileCollection>() {
                public FileCollection call() throws Exception {
                    if (project.getPlugins().hasPlugin(JavaPlugin.class)) {
                        return null;
                    } else {
                        return project.fileTree(earPluginConvention.getAppDirName());
                    }
                }
            });
        }
    });
}
 
Example #29
Source Project: pushfish-android   Author: PushFish   File: EarPlugin.java    License: BSD 2-Clause "Simplified" License 5 votes vote down vote up
private void configureWithNoJavaPluginApplied(final Project project, final EarPluginConvention earPluginConvention) {
    project.getTasks().withType(Ear.class, new Action<Ear>() {
        public void execute(final Ear task) {
            task.from(new Callable<FileCollection>() {
                public FileCollection call() throws Exception {
                    if (project.getPlugins().hasPlugin(JavaPlugin.class)) {
                        return null;
                    } else {
                        return project.fileTree(earPluginConvention.getAppDirName());
                    }
                }
            });
        }
    });
}
 
Example #30
Source Project: pushfish-android   Author: PushFish   File: EarPlugin.java    License: BSD 2-Clause "Simplified" License 5 votes vote down vote up
private void configureWithJavaPluginApplied(final Project project, final EarPluginConvention earPluginConvention, PluginContainer plugins) {
    plugins.withType(JavaPlugin.class, new Action<JavaPlugin>() {
        public void execute(JavaPlugin javaPlugin) {
            final JavaPluginConvention javaPluginConvention = project.getConvention().findPlugin(JavaPluginConvention.class);

            SourceSet sourceSet = javaPluginConvention.getSourceSets().getByName(SourceSet.MAIN_SOURCE_SET_NAME);
            sourceSet.getResources().srcDir(new Callable() {
                public Object call() throws Exception {
                    return earPluginConvention.getAppDirName();
                }
            });
            project.getTasks().withType(Ear.class, new Action<Ear>() {
                public void execute(final Ear task) {
                    task.dependsOn(new Callable<FileCollection>() {
                        public FileCollection call() throws Exception {
                            return javaPluginConvention.getSourceSets().getByName(SourceSet.MAIN_SOURCE_SET_NAME)
                                    .getRuntimeClasspath();
                        }
                    });
                    task.from(new Callable<FileCollection>() {
                        public FileCollection call() throws Exception {
                            return javaPluginConvention.getSourceSets().getByName(SourceSet.MAIN_SOURCE_SET_NAME).getOutput();
                        }
                    });
                }
            });
        }
    });
}