use of org.gradle.api.Project in project spring-boot by spring-projects.
the class DeployedPlugin method apply.
@Override
@SuppressWarnings("deprecation")
public void apply(Project project) {
project.getPlugins().apply(MavenPublishPlugin.class);
project.getPlugins().apply(MavenRepositoryPlugin.class);
PublishingExtension publishing = project.getExtensions().getByType(PublishingExtension.class);
MavenPublication mavenPublication = publishing.getPublications().create("maven", MavenPublication.class);
project.afterEvaluate((evaluated) -> {
project.getPlugins().withType(JavaPlugin.class).all((javaPlugin) -> {
if (((Jar) project.getTasks().getByName(JavaPlugin.JAR_TASK_NAME)).isEnabled()) {
project.getComponents().matching((component) -> component.getName().equals("java")).all((javaComponent) -> mavenPublication.from(javaComponent));
}
});
});
project.getPlugins().withType(JavaPlatformPlugin.class).all((javaPlugin) -> project.getComponents().matching((component) -> component.getName().equals("javaPlatform")).all((javaComponent) -> mavenPublication.from(javaComponent)));
}
use of org.gradle.api.Project in project spring-boot by spring-projects.
the class JavaConventions method configureJarManifestConventions.
private void configureJarManifestConventions(Project project) {
ExtractResources extractLegalResources = project.getTasks().create("extractLegalResources", ExtractResources.class);
extractLegalResources.getDestinationDirectory().set(project.getLayout().getBuildDirectory().dir("legal"));
extractLegalResources.setResourcesNames(Arrays.asList("LICENSE.txt", "NOTICE.txt"));
extractLegalResources.property("version", project.getVersion().toString());
SourceSetContainer sourceSets = project.getExtensions().getByType(SourceSetContainer.class);
Set<String> sourceJarTaskNames = sourceSets.stream().map(SourceSet::getSourcesJarTaskName).collect(Collectors.toSet());
Set<String> javadocJarTaskNames = sourceSets.stream().map(SourceSet::getJavadocJarTaskName).collect(Collectors.toSet());
project.getTasks().withType(Jar.class, (jar) -> project.afterEvaluate((evaluated) -> {
jar.metaInf((metaInf) -> metaInf.from(extractLegalResources));
jar.manifest((manifest) -> {
Map<String, Object> attributes = new TreeMap<>();
attributes.put("Automatic-Module-Name", project.getName().replace("-", "."));
attributes.put("Build-Jdk-Spec", SOURCE_AND_TARGET_COMPATIBILITY);
attributes.put("Built-By", "Spring");
attributes.put("Implementation-Title", determineImplementationTitle(project, sourceJarTaskNames, javadocJarTaskNames, jar));
attributes.put("Implementation-Version", project.getVersion());
manifest.attributes(attributes);
});
}));
}
use of org.gradle.api.Project in project spring-boot by spring-projects.
the class WarPluginAction method configureBootWarTask.
private TaskProvider<BootWar> configureBootWarTask(Project project) {
Configuration developmentOnly = project.getConfigurations().getByName(SpringBootPlugin.DEVELOPMENT_ONLY_CONFIGURATION_NAME);
Configuration productionRuntimeClasspath = project.getConfigurations().getByName(SpringBootPlugin.PRODUCTION_RUNTIME_CLASSPATH_CONFIGURATION_NAME);
Callable<FileCollection> classpath = () -> project.getExtensions().getByType(SourceSetContainer.class).getByName(SourceSet.MAIN_SOURCE_SET_NAME).getRuntimeClasspath().minus(providedRuntimeConfiguration(project)).minus((developmentOnly.minus(productionRuntimeClasspath))).filter(new JarTypeFileSpec());
TaskProvider<ResolveMainClassName> resolveMainClassName = ResolveMainClassName.registerForTask(SpringBootPlugin.BOOT_WAR_TASK_NAME, project, classpath);
TaskProvider<BootWar> bootWarProvider = project.getTasks().register(SpringBootPlugin.BOOT_WAR_TASK_NAME, BootWar.class, (bootWar) -> {
bootWar.setGroup(BasePlugin.BUILD_GROUP);
bootWar.setDescription("Assembles an executable war archive containing webapp" + " content, and the main classes and their dependencies.");
bootWar.providedClasspath(providedRuntimeConfiguration(project));
bootWar.setClasspath(classpath);
Provider<String> manifestStartClass = project.provider(() -> (String) bootWar.getManifest().getAttributes().get("Start-Class"));
bootWar.getMainClass().convention(resolveMainClassName.flatMap((resolver) -> manifestStartClass.isPresent() ? manifestStartClass : resolveMainClassName.get().readMainClassName()));
});
bootWarProvider.map((bootWar) -> bootWar.getClasspath());
return bootWarProvider;
}
use of org.gradle.api.Project in project spring-boot by spring-projects.
the class SpringBootExtension method buildInfo.
/**
* Creates a new {@link BuildInfo} task named {@code bootBuildInfo} and configures the
* Java plugin's {@code classes} task to depend upon it. The task is passed to the
* given {@code configurer} for further configuration.
* <p>
* By default, the task's destination dir will be a directory named {@code META-INF}
* beneath the main source set's resources output directory, and the task's project
* artifact will be the base name of the {@code bootWar} or {@code bootJar} task.
* @param configurer the task configurer
*/
public void buildInfo(Action<BuildInfo> configurer) {
TaskContainer tasks = this.project.getTasks();
TaskProvider<BuildInfo> bootBuildInfo = tasks.register("bootBuildInfo", BuildInfo.class, this::configureBuildInfoTask);
this.project.getPlugins().withType(JavaPlugin.class, (plugin) -> {
tasks.named(JavaPlugin.CLASSES_TASK_NAME).configure((task) -> task.dependsOn(bootBuildInfo));
this.project.afterEvaluate((evaluated) -> bootBuildInfo.configure((buildInfo) -> {
BuildInfoProperties properties = buildInfo.getProperties();
if (properties.getArtifact() == null) {
properties.setArtifact(determineArtifactBaseName());
}
}));
});
if (configurer != null) {
bootBuildInfo.configure(configurer);
}
}
use of org.gradle.api.Project in project tomee by apache.
the class TomEEEmbeddedTask method fixConfig.
private void fixConfig() {
final Project project = getProject();
// defaults
if (classpath == null) {
try {
classpath.add(project.getConfigurations().getByName(TomEEEmbeddedExtension.ALIAS).fileCollection());
} catch (final UnknownConfigurationException uce) {
classpath = project.getConfigurations().getByName(TomEEEmbeddedExtension.NAME);
}
}
if (docBase == null) {
docBase = new File(project.getProjectDir(), "src/main/webapp");
}
if (workDir == null) {
workDir = new File(project.getBuildDir(), "tomee-embedded/work");
}
if (dir == null) {
dir = new File(project.getBuildDir(), "tomee-embedded/run").getAbsolutePath();
}
if (modules == null || modules.isEmpty()) {
final File main = new File(project.getBuildDir(), "classes/main");
if (main.isDirectory()) {
modules = new ArrayList<>(singletonList(main));
}
}
// extension override
for (final String name : asList(TomEEEmbeddedExtension.NAME, TomEEEmbeddedExtension.ALIAS)) {
final TomEEEmbeddedExtension extension = TomEEEmbeddedExtension.class.cast(project.getExtensions().findByName(name));
if (extension != null) {
for (final Field f : TomEEEmbeddedTask.class.getDeclaredFields()) {
if (f.isAnnotationPresent(Input.class)) {
try {
final Field extField = TomEEEmbeddedExtension.class.getDeclaredField(f.getName());
if (!extField.isAccessible()) {
extField.setAccessible(true);
}
final Object val = extField.get(extension);
if (val != null) {
if (!f.isAccessible()) {
f.setAccessible(true);
}
f.set(this, val);
}
} catch (final IllegalAccessException | NoSuchFieldException e) {
getLogger().warn("No field " + f.getName() + " in " + extension, e);
}
}
}
}
}
}
Aggregations