use of org.gradle.api.plugins.JavaPluginExtension in project spring-boot by spring-projects.
the class JavaConventions method configureJavaConventions.
private void configureJavaConventions(Project project) {
if (!project.hasProperty("toolchainVersion")) {
JavaPluginExtension javaPluginExtension = project.getExtensions().getByType(JavaPluginExtension.class);
javaPluginExtension.setSourceCompatibility(JavaVersion.toVersion(SOURCE_AND_TARGET_COMPATIBILITY));
}
project.getTasks().withType(JavaCompile.class, (compile) -> {
compile.getOptions().setEncoding("UTF-8");
List<String> args = compile.getOptions().getCompilerArgs();
if (!args.contains("-parameters")) {
args.add("-parameters");
}
if (project.hasProperty("toolchainVersion")) {
compile.setSourceCompatibility(SOURCE_AND_TARGET_COMPATIBILITY);
compile.setTargetCompatibility(SOURCE_AND_TARGET_COMPATIBILITY);
}
args.addAll(Arrays.asList("-Werror", "-Xlint:unchecked", "-Xlint:deprecation", "-Xlint:rawtypes", "-Xlint:varargs"));
});
}
use of org.gradle.api.plugins.JavaPluginExtension in project spring-boot by spring-projects.
the class MavenPublishingConventions method addMavenOptionalFeature.
/**
* Add a feature that allows maven plugins to declare optional dependencies that
* appear in the POM. This is required to make m2e in Eclipse happy.
* @param project the project to add the feature to
*/
private void addMavenOptionalFeature(Project project) {
JavaPluginExtension extension = project.getExtensions().getByType(JavaPluginExtension.class);
extension.registerFeature("mavenOptional", (feature) -> feature.usingSourceSet(extension.getSourceSets().getByName("main")));
AdhocComponentWithVariants javaComponent = (AdhocComponentWithVariants) project.getComponents().findByName("java");
javaComponent.addVariantsFromConfiguration(project.getConfigurations().findByName("mavenOptionalRuntimeElements"), ConfigurationVariantDetails::mapToOptional);
}
use of org.gradle.api.plugins.JavaPluginExtension in project gradle by gradle.
the class DefaultJvmVariantBuilder method build.
void build() {
SourceSet sourceSet = this.sourceSet == null ? sourceSets.maybeCreate(name) : this.sourceSet;
boolean mainSourceSet = SourceSet.isMain(sourceSet);
String apiConfigurationName;
String implementationConfigurationName;
String apiElementsConfigurationName;
String runtimeElementsConfigurationName;
String compileOnlyConfigurationName;
String compileOnlyApiConfigurationName;
String runtimeOnlyConfigurationName;
if (mainSourceSet) {
apiConfigurationName = name + "Api";
implementationConfigurationName = name + "Implementation";
apiElementsConfigurationName = apiConfigurationName + "Elements";
runtimeElementsConfigurationName = name + "RuntimeElements";
compileOnlyConfigurationName = name + "CompileOnly";
compileOnlyApiConfigurationName = name + "CompileOnlyApi";
runtimeOnlyConfigurationName = name + "RuntimeOnly";
} else {
apiConfigurationName = sourceSet.getApiConfigurationName();
implementationConfigurationName = sourceSet.getImplementationConfigurationName();
apiElementsConfigurationName = sourceSet.getApiElementsConfigurationName();
runtimeElementsConfigurationName = sourceSet.getRuntimeElementsConfigurationName();
compileOnlyConfigurationName = sourceSet.getCompileOnlyConfigurationName();
compileOnlyApiConfigurationName = sourceSet.getCompileOnlyApiConfigurationName();
runtimeOnlyConfigurationName = sourceSet.getRuntimeOnlyConfigurationName();
}
String displayName = this.displayName == null ? name : this.displayName;
// In the general case, the following configurations are already created
// but if we're using the "main" source set, it means that the component we're creating shares
// the same source set (main) but declares its dependencies in its own buckets, so we need
// to create them
Configuration implementation = bucket("Implementation", implementationConfigurationName, displayName);
Configuration compileOnly = bucket("Compile-Only", compileOnlyConfigurationName, displayName);
Configuration compileOnlyApi = bucket("Compile-Only API", compileOnlyApiConfigurationName, displayName);
Configuration runtimeOnly = bucket("Runtime-Only", runtimeOnlyConfigurationName, displayName);
TaskProvider<Task> jarTask = registerOrGetJarTask(sourceSet, displayName);
Configuration api = exposeApi ? bucket("API", apiConfigurationName, displayName) : null;
Configuration apiElements = exposeApi ? jvmPluginServices.createOutgoingElements(apiElementsConfigurationName, builder -> {
builder.fromSourceSet(sourceSet).providesApi().withDescription("API elements for " + displayName).extendsFrom(api, compileOnlyApi).withCapabilities(capabilities).withClassDirectoryVariant().artifact(jarTask);
}) : null;
if (exposeApi) {
implementation.extendsFrom(api);
}
Configuration runtimeElements = jvmPluginServices.createOutgoingElements(runtimeElementsConfigurationName, builder -> {
builder.fromSourceSet(sourceSet).providesRuntime().withDescription("Runtime elements for " + displayName).extendsFrom(implementation, runtimeOnly).withCapabilities(capabilities).artifact(jarTask);
});
if (mainSourceSet) {
// we need to wire the compile only and runtime only to the classpath configurations
configurations.getByName(sourceSet.getCompileClasspathConfigurationName()).extendsFrom(implementation, compileOnly);
configurations.getByName(sourceSet.getRuntimeClasspathConfigurationName()).extendsFrom(implementation, runtimeOnly);
// and we also want the feature dependencies to be available on the test classpath
configurations.getByName(JavaPlugin.TEST_COMPILE_CLASSPATH_CONFIGURATION_NAME).extendsFrom(implementation, compileOnlyApi);
configurations.getByName(JavaPlugin.TEST_RUNTIME_CLASSPATH_CONFIGURATION_NAME).extendsFrom(implementation, runtimeOnly);
}
final AdhocComponentWithVariants component = findJavaComponent();
JavaPluginExtension javaPluginExtension = project.getExtensions().findByType(JavaPluginExtension.class);
configureJavaDocTask(name, sourceSet, tasks, javaPluginExtension);
if (javadocJar) {
configureDocumentationVariantWithArtifact(sourceSet.getJavadocElementsConfigurationName(), mainSourceSet ? null : name, displayName, JAVADOC, sourceSet.getJavadocJarTaskName(), tasks.named(sourceSet.getJavadocTaskName()), component);
}
if (sourcesJar) {
configureDocumentationVariantWithArtifact(sourceSet.getSourcesElementsConfigurationName(), mainSourceSet ? null : name, displayName, SOURCES, sourceSet.getSourcesJarTaskName(), sourceSet.getAllSource(), component);
}
if (published && component != null) {
if (apiElements != null) {
component.addVariantsFromConfiguration(apiElements, new JavaConfigurationVariantMapping("compile", true));
}
component.addVariantsFromConfiguration(runtimeElements, new JavaConfigurationVariantMapping("runtime", true));
}
}
Aggregations