org.gradle.api.plugins.JavaPluginConvention Java Examples
The following examples show how to use
org.gradle.api.plugins.JavaPluginConvention.
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: SourcesJarPlugin.java From gradle-plugins with MIT License | 7 votes |
@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 File: AspectJPlugin.java From gradle-plugins with MIT License | 7 votes |
@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 File: ModuleName.java From gradle-modules-plugin with MIT License | 6 votes |
Optional<String> findModuleName(Project project) { SourceSet main; try { JavaPluginConvention javaConvention = project.getConvention().getPlugin(JavaPluginConvention.class); main = javaConvention.getSourceSets().getByName(SourceSet.MAIN_SOURCE_SET_NAME); } catch (IllegalStateException | UnknownDomainObjectException e) { LOGGER.warn("Cannot obtain JavaPluginConvention", e); return Optional.empty(); } Optional<Path> moduleInfoJava = main.getAllJava() .getSourceDirectories() .getFiles() .stream() .map(sourceDir -> sourceDir.toPath().resolve("module-info.java")) .filter(Files::exists) .findAny(); String projectPath = project.getPath(); if (moduleInfoJava.isEmpty()) { LOGGER.lifecycle("Project {} => no module-info.java found", projectPath); return Optional.empty(); } return findModuleName(moduleInfoJava.get(), projectPath); }
Example #4
Source File: LombokPlugin.java From gradle-plugins with MIT License | 6 votes |
private void configureForSpotbugs(JavaPluginConvention javaPluginConvention) { lombokBasePlugin.getLombokExtension().getConfig().put("lombok.extern.findbugs.addSuppressFBWarnings", "true"); project.afterEvaluate(p -> { Object spotbugsExtension = project.getExtensions().getByName("spotbugs"); String toolVersion; if (spotbugsExtension instanceof CodeQualityExtension) { toolVersion = ((CodeQualityExtension) spotbugsExtension).getToolVersion(); } else { Property<String> toolVersionProperty = (Property<String>) new DslObject(spotbugsExtension).getAsDynamicObject().getProperty("toolVersion"); toolVersion = toolVersionProperty.get(); } javaPluginConvention.getSourceSets().all(sourceSet -> project.getDependencies().add( sourceSet.getCompileOnlyConfigurationName(), "com.github.spotbugs:spotbugs-annotations:" + toolVersion )); }); }
Example #5
Source File: SourcesJarPlugin.java From gradle-plugins with MIT License | 6 votes |
@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 #6
Source File: AspectJPlugin.java From gradle-plugins with MIT License | 6 votes |
@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 #7
Source File: MavenProjectWrapper.java From gradle-plugins with MIT License | 6 votes |
public MavenProjectWrapper(Project project, File pomFile) throws IOException, XmlPullParserException { this.project = project; this.pomFile = pomFile; MavenXpp3Reader reader = new MavenXpp3Reader(); Model model = reader.read(new FileReader(pomFile)); setModel(model); getBuild().setDirectory(project.getBuildDir().getAbsolutePath()); SourceSetContainer sourceSets = project.getConvention().getPlugin(JavaPluginConvention.class).getSourceSets(); SourceSet main = sourceSets.getByName(SourceSet.MAIN_SOURCE_SET_NAME); getBuild().setSourceDirectory(main.getJava().getSrcDirs().iterator().next().getAbsolutePath()); getBuild().setOutputDirectory(main.getJava().getOutputDir().getAbsolutePath()); SourceSet test = sourceSets.getByName(SourceSet.TEST_SOURCE_SET_NAME); getBuild().setTestSourceDirectory(test.getJava().getSrcDirs().iterator().next().getAbsolutePath()); getBuild().setTestOutputDirectory(test.getJava().getOutputDir().getAbsolutePath()); setArtifact(new ProjectArtifact(this)); }
Example #8
Source File: JSassJavaPlugin.java From gradle-plugins with MIT License | 6 votes |
@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 #9
Source File: SassCompileTask.java From GradleSassPlugin with Apache License 2.0 | 6 votes |
public void registerInSourceSets(String ...sourceSetNames) { if (sourceSetNames == null || sourceSetNames.length == 0) return; try { JavaPluginConvention javaPlugin = getProject().getConvention().getPlugin(JavaPluginConvention.class); if (javaPlugin == null) { throw new GradleException("You must apply the java plugin if you're using 'registerInSourceSets' functionality."); } for (String sourceSet : sourceSetNames) { javaPlugin.getSourceSets().getByName(sourceSet).getOutput().dir( Collections.singletonMap("builtBy", this), getOutDir() ); } } catch (Exception e) { throw new GradleException("You must apply the java plugin if you're using 'registerInSourceSets' functionality."); } }
Example #10
Source File: LombokPlugin.java From gradle-plugins with MIT License | 6 votes |
private void configureForSpotbugs(JavaPluginConvention javaPluginConvention) { lombokBasePlugin.getLombokExtension().getConfig().put("lombok.extern.findbugs.addSuppressFBWarnings", "true"); project.afterEvaluate(p -> { Object spotbugsExtension = project.getExtensions().getByName("spotbugs"); String toolVersion; if (spotbugsExtension instanceof CodeQualityExtension) { toolVersion = ((CodeQualityExtension) spotbugsExtension).getToolVersion(); } else { Property<String> toolVersionProperty = (Property<String>) new DslObject(spotbugsExtension).getAsDynamicObject().getProperty("toolVersion"); toolVersion = toolVersionProperty.get(); } javaPluginConvention.getSourceSets().all(sourceSet -> project.getDependencies().add( sourceSet.getCompileOnlyConfigurationName(), "com.github.spotbugs:spotbugs-annotations:" + toolVersion )); }); }
Example #11
Source File: MavenProjectWrapper.java From gradle-plugins with MIT License | 6 votes |
public MavenProjectWrapper(Project project, File pomFile) throws IOException, XmlPullParserException { this.project = project; this.pomFile = pomFile; MavenXpp3Reader reader = new MavenXpp3Reader(); Model model = reader.read(new FileReader(pomFile)); setModel(model); getBuild().setDirectory(project.getBuildDir().getAbsolutePath()); SourceSetContainer sourceSets = project.getConvention().getPlugin(JavaPluginConvention.class).getSourceSets(); SourceSet main = sourceSets.getByName(SourceSet.MAIN_SOURCE_SET_NAME); getBuild().setSourceDirectory(main.getJava().getSrcDirs().iterator().next().getAbsolutePath()); getBuild().setOutputDirectory(main.getJava().getOutputDir().getAbsolutePath()); SourceSet test = sourceSets.getByName(SourceSet.TEST_SOURCE_SET_NAME); getBuild().setTestSourceDirectory(test.getJava().getSrcDirs().iterator().next().getAbsolutePath()); getBuild().setTestOutputDirectory(test.getJava().getOutputDir().getAbsolutePath()); setArtifact(new ProjectArtifact(this)); }
Example #12
Source File: JSassJavaPlugin.java From gradle-plugins with MIT License | 6 votes |
@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 #13
Source File: CodeServerBuilder.java From putnami-gradle-plugin with GNU Lesser General Public License v3.0 | 6 votes |
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 #14
Source File: OptionalDependenciesPlugin.java From reactor-core with Apache License 2.0 | 6 votes |
@Override public void apply(Project project) { Configuration optional = project.getConfigurations().create(OPTIONAL_CONFIGURATION_NAME); optional.attributes((attributes) -> attributes.attribute(Usage.USAGE_ATTRIBUTE, project.getObjects().named(Usage.class, Usage.JAVA_RUNTIME))); project.getPlugins().withType(JavaPlugin.class, (javaPlugin) -> { SourceSetContainer sourceSets = project.getConvention().getPlugin(JavaPluginConvention.class) .getSourceSets(); sourceSets.all((sourceSet) -> { sourceSet.setCompileClasspath(sourceSet.getCompileClasspath().plus(optional)); sourceSet.setRuntimeClasspath(sourceSet.getRuntimeClasspath().plus(optional)); }); project.getTasks().withType(Javadoc.class) .all((javadoc) -> javadoc.setClasspath(javadoc.getClasspath().plus(optional))); }); project.getPlugins().withType(EclipsePlugin.class, (eclipsePlugin) -> project.getExtensions().getByType(EclipseModel.class) .classpath((classpath) -> classpath.getPlusConfigurations().add(optional))); }
Example #15
Source File: CpdPluginTest.java From gradle-cpd-plugin with Apache License 2.0 | 6 votes |
@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 #16
Source File: Web3jPlugin.java From web3j-gradle-plugin with Apache License 2.0 | 5 votes |
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 #17
Source File: EarPlugin.java From pushfish-android with BSD 2-Clause "Simplified" License | 5 votes |
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(); } }); } }); } }); }
Example #18
Source File: EarPlugin.java From pushfish-android with BSD 2-Clause "Simplified" License | 5 votes |
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(); } }); } }); } }); }
Example #19
Source File: GeneratorPlugin.java From doov with Apache License 2.0 | 5 votes |
@Override public void apply(Project target) { NamedDomainObjectContainer<ModelMapGenerator> container = target.container(ModelMapGenerator.class, name -> new ModelMapGenerator(name, target)); target.getExtensions().add("doovCodeGen", container); JavaCompile compileJava = target.getTasks().withType(JavaCompile.class).getByName("compileJava"); JavaPluginConvention javaPluginConvention = target.getConvention().findPlugin(JavaPluginConvention.class); SourceSet main = javaPluginConvention.getSourceSets().maybeCreate("main"); container.all(modelMap -> { ModelMapGenTask task = target.getTasks().create(modelMap.getName(), ModelMapGenTask.class); main.getJava().srcDir(modelMap.getOutputDirectory()); target.afterEvaluate(project -> { task.setClasspath(main.getCompileClasspath()); task.getBaseClassProperty().set(modelMap.getBaseClass()); task.getOutputDirectory().set(modelMap.getOutputDirectory()); task.getOutputResourceDirectory().set(modelMap.getOutputResourceDirectory()); task.getSourceClassProperty().set(modelMap.getSourceClass()); task.getFieldClassProperty().set(modelMap.getFieldClass()); task.getPackageFilter().set(modelMap.getPackageFilter()); task.getEnumFieldInfo().set(modelMap.getEnumFieldInfo()); task.getFieldPathProviderProperty().set(modelMap.getFieldPathProvider()); task.getTypeAdaptersProperty().set(modelMap.getTypeAdapters()); task.getDslModelPackage().set(modelMap.getDslModelPackage()); task.getWrapperPackage().set(modelMap.getWrapperPackage()); task.getFieldInfoPackage().set(modelMap.getFieldInfoPackage()); task.getDslEntrypointMethods().set(modelMap.getDslEntrypointMethods()); compileJava.dependsOn(task); }); }); }
Example #20
Source File: TransportPlugin.java From transport with BSD 2-Clause "Simplified" License | 5 votes |
public void apply(Project project) { TransportPluginConfig extension = project.getExtensions().create("transport", TransportPluginConfig.class, project); project.getPlugins().withType(JavaPlugin.class, (javaPlugin) -> { project.getPlugins().apply(ScalaPlugin.class); project.getPlugins().apply(DistributionPlugin.class); project.getConfigurations().create(ShadowBasePlugin.getCONFIGURATION_NAME()); JavaPluginConvention javaConvention = project.getConvention().getPlugin(JavaPluginConvention.class); SourceSet mainSourceSet = javaConvention.getSourceSets().getByName(extension.mainSourceSetName); SourceSet testSourceSet = javaConvention.getSourceSets().getByName(extension.testSourceSetName); configureBaseSourceSets(project, mainSourceSet, testSourceSet); Defaults.DEFAULT_PLATFORMS.forEach( platform -> configurePlatform(project, platform, mainSourceSet, testSourceSet, extension.outputDirFile)); }); // Disable Jacoco for platform test tasks as it is known to cause issues with Presto and Hive tests project.getPlugins().withType(JacocoPlugin.class, (jacocoPlugin) -> { Defaults.DEFAULT_PLATFORMS.forEach(platform -> { project.getTasksByName(testTaskName(platform), true).forEach(task -> { JacocoTaskExtension jacocoExtension = task.getExtensions().findByType(JacocoTaskExtension.class); if (jacocoExtension != null) { jacocoExtension.setEnabled(false); } }); }); }); }
Example #21
Source File: SpringJavaFormatPlugin.java From spring-javaformat with Apache License 2.0 | 5 votes |
private void addSourceTasks() { this.project.getPlugins().withType(JavaBasePlugin.class, (plugin) -> { Task formatAll = this.project.task(FormatTask.NAME); formatAll.setDescription(FormatTask.DESCRIPTION); Task checkAll = this.project.task(CheckTask.NAME); checkAll.setDescription(CheckTask.DESCRIPTION); this.project.getTasks().getByName(JavaBasePlugin.CHECK_TASK_NAME).dependsOn(checkAll); this.project.getConvention().getPlugin(JavaPluginConvention.class).getSourceSets() .all((sourceSet) -> addSourceTasks(sourceSet, checkAll, formatAll)); }); }
Example #22
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 #23
Source File: QuarkusGradleUtils.java From quarkus with Apache License 2.0 | 5 votes |
public static SourceSet getSourceSet(Project project, String sourceSetName) { final Convention convention = project.getConvention(); JavaPluginConvention javaConvention = convention.findPlugin(JavaPluginConvention.class); if (javaConvention == null) { throw new IllegalArgumentException("The project does not include the Java plugin"); } return javaConvention.getSourceSets().getByName(sourceSetName); }
Example #24
Source File: QuarkusPluginExtension.java From quarkus with Apache License 2.0 | 5 votes |
public Path appJarOrClasses() { final Jar jarTask = (Jar) project.getTasks().findByName(JavaPlugin.JAR_TASK_NAME); if (jarTask == null) { throw new RuntimeException("Failed to locate task 'jar' in the project."); } final Provider<RegularFile> jarProvider = jarTask.getArchiveFile(); Path classesDir = null; if (jarProvider.isPresent()) { final File f = jarProvider.get().getAsFile(); if (f.exists()) { classesDir = f.toPath(); } } if (classesDir == null) { final Convention convention = project.getConvention(); JavaPluginConvention javaConvention = convention.findPlugin(JavaPluginConvention.class); if (javaConvention != null) { final SourceSet mainSourceSet = javaConvention.getSourceSets().getByName(SourceSet.MAIN_SOURCE_SET_NAME); final String classesPath = QuarkusGradleUtils.getClassesDir(mainSourceSet, jarTask.getTemporaryDir()); if (classesPath != null) { classesDir = Paths.get(classesPath); } } } if (classesDir == null) { throw new RuntimeException("Failed to locate project's classes directory"); } return classesDir; }
Example #25
Source File: QuarkusPluginExtension.java From quarkus with Apache License 2.0 | 5 votes |
public File outputDirectory() { if (outputDirectory == null) { outputDirectory = getLastFile(project.getConvention().getPlugin(JavaPluginConvention.class) .getSourceSets().getByName(SourceSet.MAIN_SOURCE_SET_NAME).getOutput().getClassesDirs()); } return outputDirectory; }
Example #26
Source File: QuarkusPluginExtension.java From quarkus with Apache License 2.0 | 5 votes |
public File outputConfigDirectory() { if (outputConfigDirectory == null) { outputConfigDirectory = project.getConvention().getPlugin(JavaPluginConvention.class) .getSourceSets().getByName(SourceSet.MAIN_SOURCE_SET_NAME).getOutput().getResourcesDir(); } return outputConfigDirectory; }
Example #27
Source File: QuarkusPluginExtension.java From quarkus with Apache License 2.0 | 5 votes |
public File sourceDir() { if (sourceDir == null) { sourceDir = getLastFile(project.getConvention().getPlugin(JavaPluginConvention.class) .getSourceSets().getByName(SourceSet.MAIN_SOURCE_SET_NAME).getAllJava().getSourceDirectories()); } return sourceDir; }
Example #28
Source File: SchemaGenPlugin.java From gradle-plugins with Apache License 2.0 | 5 votes |
@Override public void apply(Project project) { GenerateSchemaTask generateSchemaTask = project.getTasks().create(GenerateSchemaTask.NAME, GenerateSchemaTask.class); JavaPluginConvention javaConvention = project.getConvention().getPlugin(JavaPluginConvention.class); SourceSet mainSourceSet = javaConvention.getSourceSets().getByName(SourceSet.MAIN_SOURCE_SET_NAME); generateSchemaTask.setClasses(mainSourceSet.getOutput().getClassesDirs()); SchemaGenExtension extension = new SchemaGenExtension(); extension.project = project; project.getExtensions().add("jpaSchemaGen", extension); project.afterEvaluate(p -> { // jar dependency needs to be deferred as its depends on the plugin extension configuration if (extension.getContinuousMode()) { Task processResources = project.getTasks().getByName("processResources"); processResources.finalizedBy(generateSchemaTask); } // dependant configuration is deffered as it is set be the user through the extension Configuration schemaGenConfig = project.getConfigurations().getByName(extension.getConfiguration()); generateSchemaTask.dependsOn(schemaGenConfig); generateSchemaTask.setDependencies(schemaGenConfig); }); }
Example #29
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 #30
Source File: JavadocJarPlugin.java From gradle-plugins with MIT License | 5 votes |
@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" )); }); }); }); }