use of org.gradle.api.plugins.JavaPlugin in project curiostack by curioswitch.
the class CuriostackPlugin method setupJavaProject.
private static void setupJavaProject(Project project) {
PluginContainer plugins = project.getPlugins();
plugins.apply(AptPlugin.class);
plugins.apply(AptIdeaPlugin.class);
plugins.apply(BaselineIdea.class);
plugins.apply(DependencyManagementPlugin.class);
plugins.apply(ErrorPronePlugin.class);
plugins.apply(LicensePlugin.class);
plugins.apply(SpotlessPlugin.class);
plugins.apply(VersionsPlugin.class);
project.getTasks().withType(JavaCompile.class, task -> {
task.getOptions().setIncremental(true);
task.getOptions().getCompilerArgs().addAll(ImmutableList.of("-XepDisableWarningsInGeneratedCode", "-XepExcludedPaths:(.*/build/.*|.*/gen-src/.*)", "-Xep:AutoFactoryAtInject:ERROR", "-Xep:ClassName:ERROR", "-Xep:ComparisonContractViolated:ERROR", "-Xep:DepAnn:ERROR", "-Xep:DivZero:ERROR", "-Xep:EmptyIf:ERROR", "-Xep:FuzzyEqualsShouldNotBeUsedInEqualsMethod:ERROR", "-Xep:InjectInvalidTargetingOnScopingAnnotation:ERROR", "-Xep:InjectScopeAnnotationOnInterfaceOrAbstractClass:ERROR", "-Xep:InsecureCryptoUsage:ERROR", "-Xep:IterablePathParameter:ERROR", "-Xep:LongLiteralLowerCaseSuffix:ERROR", "-Xep:NumericEquality:ERROR", "-Xep:ParameterPackage:ERROR", "-Xep:ProtoStringFieldReferenceEquality:ERROR", "-Xep:AssistedInjectAndInjectOnConstructors:ERROR", "-Xep:BigDecimalLiteralDouble:ERROR", "-Xep:ConstructorLeaksThis:ERROR", "-Xep:InconsistentOverloads:ERROR", "-Xep:MissingDefault:ERROR", "-Xep:PrimitiveArrayPassedToVarargsMethod:ERROR", "-Xep:RedundantThrows:ERROR", "-Xep:StaticQualifiedUsingExpression:ERROR", "-Xep:StringEquality:ERROR", "-Xep:TestExceptionChecker:ERROR", "-Xep:FieldMissingNullable:ERROR", "-Xep:LambdaFunctionalInterface:ERROR", "-Xep:MethodCanBeStatic:ERROR", "-Xep:MixedArrayDimensions:ERROR", "-Xep:MultiVariableDeclaration:ERROR", "-Xep:MultipleTopLevelClasses:ERROR", "-Xep:MultipleUnaryOperatorsInMethodCall:ERROR", "-Xep:PackageLocation:ERROR", "-Xep:ParameterComment:ERROR", "-Xep:ParameterNotNullable:ERROR", "-Xep:PrivateConstructorForUtilityClass:ERROR", "-Xep:RemoveUnusedImports:ERROR", "-Xep:ReturnMissingNullable:ERROR", "-Xep:SwitchDefault:ERROR", "-Xep:ThrowsUncheckedException:ERROR", "-Xep:UngroupedOverloads:ERROR", "-Xep:UnnecessaryStaticImport:ERROR", "-Xep:UseBinds:ERROR", "-Xep:WildcardImport:ERROR"));
project.getTasks().withType(SpotlessTask.class, spotlessTask -> spotlessTask.dependsOn(task));
});
JavaPluginConvention javaPlugin = project.getConvention().getPlugin(JavaPluginConvention.class);
javaPlugin.setSourceCompatibility(JavaVersion.VERSION_1_9);
javaPlugin.setTargetCompatibility(JavaVersion.VERSION_1_9);
Test test = project.getTasks().withType(Test.class).getByName("test");
if (project.getRootProject().hasProperty("updateSnapshots")) {
test.jvmArgs(ImmutableList.of("-Dorg.curioswitch.testing.updateSnapshots=true"));
}
test.useJUnitPlatform(platform -> platform.includeEngines("junit-jupiter", "junit-vintage"));
// While Gradle attempts to generate a unique module name automatically,
// it doesn't seem to always work properly, so we just always use unique
// module names.
project.getPlugins().withType(IdeaPlugin.class, plugin -> {
IdeaModule module = plugin.getModel().getModule();
String moduleName = project.getName();
Project ancestor = project.getParent();
while (ancestor != null && ancestor != project.getRootProject()) {
moduleName = ancestor.getName() + "-" + moduleName;
ancestor = ancestor.getParent();
}
module.setName(moduleName);
project.getTasks().getByName("clean").doLast(unused -> project.file(project.getName() + ".iml").delete());
new DslObject(module).getConvention().getPlugin(ModuleAptConvention.class).getApt().setAddAptDependencies(false);
});
DependencyManagementExtension dependencyManagement = project.getExtensions().getByType(DependencyManagementExtension.class);
dependencyManagement.dependencies(dependencies -> {
for (DependencySet set : StandardDependencies.DEPENDENCY_SETS) {
dependencies.dependencySet(ImmutableMap.of("group", set.group(), "version", set.version()), dependencySet -> set.modules().forEach(dependencySet::entry));
}
StandardDependencies.DEPENDENCIES.forEach(dependencies::dependency);
});
// Pretty much all java code needs at least the Generated annotation.
project.getDependencies().add(JavaPlugin.IMPLEMENTATION_CONFIGURATION_NAME, "javax.annotation:javax.annotation-api");
project.afterEvaluate(CuriostackPlugin::addStandardJavaTestDependencies);
project.getConfigurations().all(configuration -> configuration.exclude(ImmutableMap.of("group", "com.google.guava", "module", "guava-jdk5")));
Javadoc javadoc = (Javadoc) project.getTasks().getByName("javadoc");
CoreJavadocOptions options = (CoreJavadocOptions) javadoc.getOptions();
options.quiet();
options.addBooleanOption("Xdoclint:all,-missing", true);
project.getTasks().create("javadocJar", Jar.class, javadocJar -> {
javadocJar.dependsOn(javadoc);
javadocJar.setClassifier("javadoc");
javadocJar.from(javadoc.getDestinationDir());
});
SourceSetContainer sourceSets = javaPlugin.getSourceSets();
project.getTasks().create("sourceJar", Jar.class, sourceJar -> {
sourceJar.setClassifier("sources");
sourceJar.from(sourceSets.getByName(SourceSet.MAIN_SOURCE_SET_NAME).getAllSource());
});
SpotlessExtension spotless = project.getExtensions().getByType(SpotlessExtension.class);
spotless.java((extension) -> extension.googleJavaFormat(GOOGLE_JAVA_FORMAT_VERSION));
project.getTasks().create("resolveDependencies", resolveDependencies -> resolveDependencies.doLast(unused -> {
project.getConfigurations().all(configuration -> {
if (configuration.isCanBeResolved()) {
configuration.resolve();
}
});
}));
// Protobuf plugin doesn't add proto sourceset to allSource, which seems like an omission.
// We add it to make sure license plugin picks up the files.
project.getPlugins().withType(ProtobufPlugin.class, unused -> {
for (SourceSet sourceSet : sourceSets) {
sourceSet.getAllSource().source(((ExtensionAware) sourceSet).getExtensions().getByType(ProtobufSourceDirectorySet.class));
}
});
project.getPlugins().withType(JMHPlugin.class, unused -> {
JMHPluginExtension jmh = project.getExtensions().getByType(JMHPluginExtension.class);
// Benchmarks are usually very small and converge quickly. If this stops being the
// case
// these numbers can be adjusted.
jmh.setFork(2);
jmh.setIterations(5);
jmh.setProfilers(ImmutableList.of("hs_comp"));
jmh.setJmhVersion("1.19");
Object jmhRegex = project.getRootProject().findProperty("jmhRegex");
if (jmhRegex != null) {
jmh.setInclude((String) jmhRegex);
}
// We will use the jmhManaged for any dependencies that should only be applied to JMH
// but should be resolved by our managed dependencies. We need a separate
// configuration
// to be able to provide the resolution workaround described below.
Configuration jmhManaged = project.getConfigurations().create("jmhManaged");
Configuration jmhConfiguration = project.getConfigurations().getByName("jmh");
jmhConfiguration.extendsFrom(jmhManaged);
// JMH plugin uses a detached configuration to build an uber-jar, which
// dependencyManagement
// doesn't know about. Work around this by forcing parent configurations to be
// resolved and
// added directly to the jmh configuration, which overwrites the otherwise
// unresolvable
// dependency.
project.afterEvaluate(p -> {
jmhConfiguration.getExtendsFrom().forEach(parent -> {
parent.getResolvedConfiguration().getFirstLevelModuleDependencies().forEach(dep -> {
project.getDependencies().add("jmh", dep.getModule().toString());
});
});
});
});
project.getPlugins().withType(JooqPlugin.class, unused -> {
project.getTasks().withType(JooqTask.class, t -> {
for (String dependency : ImmutableList.of("javax.activation:activation", "javax.xml.bind:jaxb-api", "com.sun.xml.bind:jaxb-core", "com.sun.xml.bind:jaxb-impl", "mysql:mysql-connector-java", // Not sure why this isn't automatically added.
"com.google.guava:guava", "com.google.cloud.sql:mysql-socket-factory")) {
project.getDependencies().add("jooqRuntime", dependency);
}
});
});
// It is very common to want to pass in command line system properties to the binary, so just
// always forward properties. It won't affect production since no one runs binaries via Gradle
// in production.
project.getTasks().withType(JavaExec.class, task -> System.getProperties().entrySet().stream().filter(entry -> !entry.getKey().equals("java.endorsed.dirs")).forEach(entry -> task.systemProperty((String) entry.getKey(), entry.getValue())));
}
use of org.gradle.api.plugins.JavaPlugin in project gradle by gradle.
the class OsgiPlugin method apply.
public void apply(final Project project) {
project.getPluginManager().apply(JavaBasePlugin.class);
final OsgiPluginConvention osgiConvention = new OsgiPluginConvention((ProjectInternal) project);
project.getConvention().getPlugins().put("osgi", osgiConvention);
project.getPlugins().withType(JavaPlugin.class, new Action<JavaPlugin>() {
@Override
public void execute(JavaPlugin javaPlugin) {
// When creating the OSGi manifest, we must have a single view of all of the classes included in the jar.
Sync prepareOsgiClasses = project.getTasks().create("osgiClasses", Sync.class);
FileCollection classes = project.getConvention().getPlugin(JavaPluginConvention.class).getSourceSets().getByName("main").getOutput().getClassesDirs();
File singleClassesDirectory = new File(project.getBuildDir(), "osgi-classes");
prepareOsgiClasses.setDescription("Prepares a single classes directory required for OSGi analysis.");
prepareOsgiClasses.from(classes);
prepareOsgiClasses.into(singleClassesDirectory);
Jar jarTask = (Jar) project.getTasks().getByName("jar");
jarTask.dependsOn(prepareOsgiClasses);
OsgiManifest osgiManifest = osgiConvention.osgiManifest();
osgiManifest.setClassesDir(singleClassesDirectory);
osgiManifest.setClasspath(project.getConfigurations().getByName("runtime"));
jarTask.setManifest(osgiManifest);
}
});
}
use of org.gradle.api.plugins.JavaPlugin in project gradle-apt-plugin by tbroyer.
the class AptPlugin25to211 method ensureCompileOnlyConfiguration.
@Override
protected void ensureCompileOnlyConfiguration(final Project project, final SourceSet sourceSet, AptPlugin.AptSourceSetConvention convention) {
Configuration configuration = project.getConfigurations().create(convention.getCompileOnlyConfigurationName());
configuration.setVisible(false);
configuration.setDescription("Compile-only classpath for " + sourceSet.getName());
configuration.extendsFrom(project.getConfigurations().findByName(sourceSet.getCompileConfigurationName()));
sourceSet.setCompileClasspath(configuration);
if (SourceSet.TEST_SOURCE_SET_NAME.equals(sourceSet.getName())) {
final Configuration conf = configuration;
project.getPlugins().withType(JavaPlugin.class, new Action<JavaPlugin>() {
@Override
public void execute(JavaPlugin javaPlugin) {
sourceSet.setCompileClasspath(project.files(project.getConvention().getPlugin(JavaPluginConvention.class).getSourceSets().getByName(SourceSet.MAIN_SOURCE_SET_NAME).getOutput(), conf));
}
});
}
}
use of org.gradle.api.plugins.JavaPlugin in project coffeenet-starter by coffeenet.
the class ConventionsPlugin method applyMavenConventions.
private void applyMavenConventions(Project project) {
// J-
// @formatter:off
project.getPlugins().withType(MavenPublishPlugin.class, (mavenPublish) -> {
PublishingExtension publishing = project.getExtensions().getByType(PublishingExtension.class);
publishing.getPublications().withType(MavenPublication.class).all((publication) -> {
customizePom(publication.getPom(), project);
});
});
project.getPlugins().withType(JavaPlugin.class).all((javaPlugin) -> {
JavaPluginExtension extension = project.getExtensions().getByType(JavaPluginExtension.class);
extension.withJavadocJar();
extension.withSourcesJar();
});
// @formatter:on
// J+
}
use of org.gradle.api.plugins.JavaPlugin in project spring-boot by spring-projects.
the class MavenPublishingConventions method apply.
void apply(Project project) {
project.getPlugins().withType(MavenPublishPlugin.class).all((mavenPublish) -> {
PublishingExtension publishing = project.getExtensions().getByType(PublishingExtension.class);
if (project.hasProperty("deploymentRepository")) {
publishing.getRepositories().maven((mavenRepository) -> {
mavenRepository.setUrl(project.property("deploymentRepository"));
mavenRepository.setName("deployment");
});
}
publishing.getPublications().withType(MavenPublication.class).all((mavenPublication) -> customizeMavenPublication(mavenPublication, project));
project.getPlugins().withType(JavaPlugin.class).all((javaPlugin) -> {
JavaPluginExtension extension = project.getExtensions().getByType(JavaPluginExtension.class);
extension.withJavadocJar();
extension.withSourcesJar();
});
});
}
Aggregations