Java Code Examples for org.gradle.api.plugins.JavaPluginConvention#getSourceSets()
The following examples show how to use
org.gradle.api.plugins.JavaPluginConvention#getSourceSets() .
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 File: QuarkusTestNative.java From quarkus with Apache License 2.0 | 5 votes |
public QuarkusTestNative() { setDescription("Runs native image tests"); setGroup("verification"); JavaPluginConvention javaPlugin = getProject().getConvention().getPlugin(JavaPluginConvention.class); SourceSetContainer sourceSets = javaPlugin.getSourceSets(); SourceSet sourceSet = sourceSets.findByName(QuarkusPlugin.NATIVE_TEST_SOURCE_SET_NAME); setTestClassesDirs(sourceSet.getOutput().getClassesDirs()); setClasspath(sourceSet.getRuntimeClasspath()); }
Example 2
Source File: CodeGeneratorPlugin.java From gradle-plugins with MIT License | 5 votes |
@Override public void apply(Project project) { CodeGeneratorConfiguration codeGenerator = project.getExtensions().create("codeGenerator", CodeGeneratorConfiguration.class, project.getObjects()); Configuration codeGeneratorConfiguration = project.getConfigurations().create("codeGenerator"); JavaPluginConvention plugin = project.getConvention().getPlugin(JavaPluginConvention.class); for (SourceSet sourceSet : plugin.getSourceSets()) { String outputDir = project.getBuildDir() + "/generated-src/generator/" + sourceSet.getName(); File outputDirFile = new File(outputDir); project.getLogger().debug("Using output dir {}", outputDir); File inputDir = new File(project.getProjectDir() + "/src/code-generator/" + sourceSet.getName()); sourceSet.getJava().srcDir(inputDir); sourceSet.getJava().srcDir(outputDirFile); project.getLogger().debug("Using input dir {}", inputDir); String taskName = sourceSet.getTaskName("generate", "Code"); TaskProvider<GenerateCodeTask> generate = project.getTasks().register(taskName, GenerateCodeTask.class, s -> { s.setGroup("generate"); s.getOutputDir().set(outputDirFile); if(inputDir.isDirectory()) { s.getInputDir().set(inputDir); } s.getSourceSet().set(sourceSet.getName()); s.getCodeGeneratorClasspath().from(codeGeneratorConfiguration); s.getConfigurationValues().set(codeGenerator.getConfigurationValues()); s.dependsOn(codeGeneratorConfiguration); }); project.getTasks().named(sourceSet.getCompileJavaTaskName(), t -> t.dependsOn(generate)); } }
Example 3
Source File: CodeGeneratorPlugin.java From gradle-plugins with MIT License | 5 votes |
@Override public void apply(Project project) { CodeGeneratorConfiguration codeGenerator = project.getExtensions().create("codeGenerator", CodeGeneratorConfiguration.class, project.getObjects()); Configuration codeGeneratorConfiguration = project.getConfigurations().create("codeGenerator"); JavaPluginConvention plugin = project.getConvention().getPlugin(JavaPluginConvention.class); for (SourceSet sourceSet : plugin.getSourceSets()) { String outputDir = project.getBuildDir() + "/generated-src/generator/" + sourceSet.getName(); File outputDirFile = new File(outputDir); project.getLogger().debug("Using output dir {}", outputDir); File inputDir = new File(project.getProjectDir() + "/src/code-generator/" + sourceSet.getName()); sourceSet.getJava().srcDir(inputDir); sourceSet.getJava().srcDir(outputDirFile); project.getLogger().debug("Using input dir {}", inputDir); String taskName = sourceSet.getTaskName("generate", "Code"); TaskProvider<GenerateCodeTask> generate = project.getTasks().register(taskName, GenerateCodeTask.class, s -> { s.setGroup("generate"); s.getOutputDir().set(outputDirFile); if(inputDir.isDirectory()) { s.getInputDir().set(inputDir); } s.getSourceSet().set(sourceSet.getName()); s.getCodeGeneratorClasspath().from(codeGeneratorConfiguration); s.getConfigurationValues().set(codeGenerator.getConfigurationValues()); s.dependsOn(codeGeneratorConfiguration); }); project.getTasks().named(sourceSet.getCompileJavaTaskName(), t -> t.dependsOn(generate)); } }
Example 4
Source File: GradleProject.java From juniversal with MIT License | 5 votes |
public SourceSet getSourceSet(SourceType sourceType) { JavaPluginConvention javaPluginConvention; try { javaPluginConvention = project.getConvention().getPlugin(JavaPluginConvention.class); } catch (IllegalStateException e) { throw new RuntimeException("Gradle project apparently isn't a Java project--it doesn't use the Java plugin"); } SourceSetContainer sourceSets = javaPluginConvention.getSourceSets(); return sourceSets.getByName(getSourceSetName(sourceType)); }
Example 5
Source File: QuarkusDev.java From quarkus with Apache License 2.0 | 4 votes |
private void addLocalProject(Project project, DevModeContext context, Set<AppArtifactKey> addeDeps, boolean root) { final AppArtifactKey key = new AppArtifactKey(project.getGroup().toString(), project.getName()); if (addeDeps.contains(key)) { return; } final JavaPluginConvention javaConvention = project.getConvention().findPlugin(JavaPluginConvention.class); if (javaConvention == null) { return; } SourceSetContainer sourceSets = javaConvention.getSourceSets(); SourceSet mainSourceSet = sourceSets.getByName(SourceSet.MAIN_SOURCE_SET_NAME); Set<String> sourcePaths = new HashSet<>(); for (File sourceDir : mainSourceSet.getAllJava().getSrcDirs()) { if (sourceDir.exists()) { sourcePaths.add(sourceDir.getAbsolutePath()); } } //TODO: multiple resource directories final File resourcesSrcDir = mainSourceSet.getResources().getSourceDirectories().getSingleFile(); if (sourcePaths.isEmpty() && !resourcesSrcDir.exists()) { return; } String classesDir = QuarkusGradleUtils.getClassesDir(mainSourceSet, project.getBuildDir()); final String resourcesOutputPath; if (resourcesSrcDir.exists()) { resourcesOutputPath = mainSourceSet.getOutput().getResourcesDir().getAbsolutePath(); if (!Files.exists(Paths.get(classesDir))) { // currently classesDir can't be null and is expected to exist classesDir = resourcesOutputPath; } } else { // currently resources dir should exist resourcesOutputPath = classesDir; } DevModeContext.ModuleInfo wsModuleInfo = new DevModeContext.ModuleInfo(key, project.getName(), project.getProjectDir().getAbsolutePath(), sourcePaths, classesDir, resourcesSrcDir.getAbsolutePath(), resourcesOutputPath); if (root) { context.setApplicationRoot(wsModuleInfo); } else { context.getAdditionalModules().add(wsModuleInfo); } addeDeps.add(key); }