Search in sources :

Example 1 with RUNTIME_CLASSPATH_CONFIGURATION_NAME

use of org.gradle.api.plugins.JavaPlugin.RUNTIME_CLASSPATH_CONFIGURATION_NAME in project ehcache3 by ehcache.

the class PackagePlugin method createPackage.

private void createPackage(Project project, Optional<VariantPlugin.Variant> variant) {
    String name = variant.map(VariantPlugin.Variant::getName).orElse(null);
    ServiceRegistry projectServices = ((ProjectInternal) project).getServices();
    JvmPluginServices jvmPluginServices = projectServices.get(JvmPluginServices.class);
    ConfigurationBucketSet packageBuckets = ConfigurationBucketSet.bucketsFor(project, name, CONTENTS_KIND);
    Configuration contentsCompileClasspath = jvmPluginServices.createResolvableConfiguration(lower(camel(name, CONTENTS_KIND, COMPILE_CLASSPATH_CONFIGURATION_NAME)), builder -> builder.extendsFrom(packageBuckets.bucket(CONTENTS_KIND)).requiresJavaLibrariesAPI());
    Configuration contentsRuntimeClasspath = jvmPluginServices.createResolvableConfiguration(lower(camel(name, CONTENTS_KIND, RUNTIME_CLASSPATH_CONFIGURATION_NAME)), builder -> builder.extendsFrom(packageBuckets.bucket(CONTENTS_KIND)).requiresJavaLibrariesRuntime());
    Configuration contentsSourcesFiles = jvmPluginServices.createResolvableConfiguration(lower(camel(name, CONTENTS_KIND, "sourcesFiles")), builder -> builder.extendsFrom(packageBuckets.bucket(CONTENTS_KIND)).requiresAttributes(refiner -> refiner.documentation(SOURCES)));
    TaskProvider<ShadowJar> shadowJar = project.getTasks().register(lower(camel(name, "jar")), ShadowJar.class, shadow -> {
        shadow.setGroup(BasePlugin.BUILD_GROUP);
        shadow.getArchiveClassifier().set(name);
        shadow.setConfigurations(Collections.singletonList(contentsRuntimeClasspath));
        shadow.relocate("org.terracotta.statistics.", "org.ehcache.shadow.org.terracotta.statistics.");
        shadow.relocate("org.terracotta.offheapstore.", "org.ehcache.shadow.org.terracotta.offheapstore.");
        shadow.relocate("org.terracotta.context.", "org.ehcache.shadow.org.terracotta.context.");
        shadow.relocate("org.terracotta.utilities.", "org.ehcache.shadow.org.terracotta.utilities.");
        shadow.mergeServiceFiles();
        shadow.exclude("META-INF/MANIFEST.MF", "LICENSE", "NOTICE");
        // LICENSE is included in root gradle build
        shadow.from(new File(project.getRootDir(), "NOTICE"));
        shadow.setDuplicatesStrategy(DuplicatesStrategy.EXCLUDE);
    });
    Configuration apiElements = jvmPluginServices.createOutgoingElements(lower(camel(name, API_ELEMENTS_CONFIGURATION_NAME)), builder -> builder.extendsFrom(packageBuckets.api()).extendsFrom(packageBuckets.compileOnlyApi()).published().providesApi().artifact(shadowJar));
    configureDefaultTargetPlatform(apiElements, 8);
    Configuration compileClasspath = jvmPluginServices.createResolvableConfiguration(lower(camel(name, COMPILE_CLASSPATH_CONFIGURATION_NAME)), builder -> builder.extendsFrom(packageBuckets.implementation()).extendsFrom(packageBuckets.compileOnly()).requiresJavaLibrariesRuntime());
    Configuration runtimeElements = jvmPluginServices.createOutgoingElements(lower(camel(name, RUNTIME_ELEMENTS_CONFIGURATION_NAME)), builder -> builder.extendsFrom(packageBuckets.implementation()).extendsFrom(packageBuckets.runtimeOnly()).published().providesRuntime().artifact(shadowJar));
    configureDefaultTargetPlatform(runtimeElements, 8);
    Configuration runtimeClasspath = jvmPluginServices.createResolvableConfiguration(lower(camel(name, RUNTIME_CLASSPATH_CONFIGURATION_NAME)), builder -> builder.extendsFrom(packageBuckets.implementation()).extendsFrom(packageBuckets.runtimeOnly()).requiresJavaLibrariesRuntime());
    Provider<FileCollection> sourcesTree = project.provider(() -> contentsSourcesFiles.getResolvedConfiguration().getLenientConfiguration().getAllModuleDependencies().stream().flatMap(d -> d.getModuleArtifacts().stream()).map(artifact -> {
        try {
            return Optional.of(artifact.getFile());
        } catch (ArtifactResolveException e) {
            return Optional.<File>empty();
        }
    }).filter(Optional::isPresent).map(Optional::get).distinct().map(file -> {
        if (file.isFile()) {
            return project.zipTree(file);
        } else {
            return project.fileTree(file);
        }
    }).reduce(FileTree::plus).orElse(project.files().getAsFileTree()));
    TaskProvider<Sync> sources = project.getTasks().register(lower(camel(name, "sources")), Sync.class, sync -> {
        sync.dependsOn(contentsSourcesFiles);
        sync.from(sourcesTree, spec -> spec.exclude("META-INF/**", "LICENSE", "NOTICE"));
        sync.into(project.getLayout().getBuildDirectory().dir(lower(camel(name, "sources"))));
    });
    TaskProvider<Jar> sourcesJar = project.getTasks().register(lower(camel(name, "sourcesJar")), Jar.class, jar -> {
        jar.setGroup(BasePlugin.BUILD_GROUP);
        jar.from(sources);
        jar.from(shadowJar, spec -> spec.include("META-INF/**", "LICENSE", "NOTICE"));
        jar.getArchiveClassifier().set(kebab(name, "sources"));
    });
    Configuration sourcesElements = jvmPluginServices.createOutgoingElements(lower(camel(name, SOURCES_ELEMENTS_CONFIGURATION_NAME)), builder -> builder.published().artifact(sourcesJar).providesAttributes(attributes -> attributes.documentation(SOURCES).asJar()));
    TaskProvider<Javadoc> javadoc = project.getTasks().register(lower(camel(name, "javadoc")), Javadoc.class, task -> {
        task.setGroup(JavaBasePlugin.DOCUMENTATION_GROUP);
        task.setTitle(project.getName() + " " + project.getVersion() + " API");
        task.source(sources);
        task.include("**/*.java");
        task.setClasspath(contentsCompileClasspath.plus(compileClasspath));
        task.setDestinationDir(new File(project.getBuildDir(), "docs/" + lower(camel(name, "javadoc"))));
    });
    TaskProvider<Jar> javadocJar = project.getTasks().register(lower(camel(name, "javadocJar")), Jar.class, jar -> {
        jar.setGroup(BasePlugin.BUILD_GROUP);
        jar.from(javadoc);
        jar.getArchiveClassifier().set(kebab(name, "javadoc"));
    });
    Configuration javadocElements = jvmPluginServices.createOutgoingElements(lower(camel(name, JAVADOC_ELEMENTS_CONFIGURATION_NAME)), builder -> builder.published().artifact(javadocJar).providesAttributes(attributes -> attributes.documentation(JAVADOC).asJar()));
    shadowJar.configure(shadow -> {
        OsgiManifestJarExtension osgiExtension = new OsgiManifestJarExtension(shadow);
        osgiExtension.getClasspath().from(runtimeClasspath);
        osgiExtension.getSources().from(sources);
        BndConvention.bundleDefaults(project).execute(osgiExtension.getInstructions());
    });
    project.getComponents().named("java", AdhocComponentWithVariants.class, java -> {
        java.addVariantsFromConfiguration(apiElements, variantDetails -> {
            variantDetails.mapToMavenScope("compile");
            variant.ifPresent(v -> variantDetails.mapToOptional());
        });
        java.addVariantsFromConfiguration(runtimeElements, variantDetails -> {
            variantDetails.mapToMavenScope("runtime");
            variant.ifPresent(v -> variantDetails.mapToOptional());
        });
        java.addVariantsFromConfiguration(sourcesElements, variantDetails -> {
        });
        java.addVariantsFromConfiguration(javadocElements, variantDetails -> {
        });
    });
    if (variant.isPresent()) {
        VariantPlugin.Variant v = variant.get();
        ConfigurationBucketSet commonBuckets = ConfigurationBucketSet.bucketsFor(project, COMMON_KIND, CONTENTS_KIND);
        packageBuckets.extendFrom(commonBuckets);
        v.getConfigTraits().configureEach(trait -> packageBuckets.extendFrom(ConfigurationBucketSet.bucketsFor(project, camel(trait, "trait"))));
        v.getCapabilities().configureEach(capability -> {
            apiElements.getOutgoing().capability(capability);
            runtimeElements.getOutgoing().capability(capability);
            sourcesElements.getOutgoing().capability(capability);
            javadocElements.getOutgoing().capability(capability);
        });
    } else {
        project.getPlugins().withType(VariantPlugin.class).configureEach(variantPlugin -> {
            project.getExtensions().configure(VariantPlugin.VariantExtension.class, variants -> {
                VariantPlugin.Variant v = variants.getDefaultVariant();
                ConfigurationBucketSet commonBuckets = ConfigurationBucketSet.bucketsFor(project, COMMON_KIND, CONTENTS_KIND);
                packageBuckets.extendFrom(commonBuckets);
                v.getConfigTraits().configureEach(trait -> packageBuckets.extendFrom(ConfigurationBucketSet.bucketsFor(project, camel(trait, "trait"))));
                v.getCapabilities().configureEach(capability -> {
                    apiElements.getOutgoing().capability(capability);
                    runtimeElements.getOutgoing().capability(capability);
                    sourcesElements.getOutgoing().capability(capability);
                    javadocElements.getOutgoing().capability(capability);
                });
            });
        });
    }
    project.getTasks().named(LifecycleBasePlugin.ASSEMBLE_TASK_NAME).configure(task -> {
        task.dependsOn(shadowJar);
        task.dependsOn(javadocJar);
        task.dependsOn(sourcesJar);
    });
}
Also used : PluginUtils.camel(org.ehcache.build.util.PluginUtils.camel) MavenPublishPlugin(org.gradle.api.publish.maven.plugins.MavenPublishPlugin) SOURCES(org.gradle.api.attributes.DocsType.SOURCES) AdhocComponentWithVariants(org.gradle.api.component.AdhocComponentWithVariants) BndConvention(org.ehcache.build.conventions.BndConvention) Provider(org.gradle.api.provider.Provider) PublishingExtension(org.gradle.api.publish.PublishingExtension) Javadoc(org.gradle.api.tasks.javadoc.Javadoc) JavaBasePlugin(org.gradle.api.plugins.JavaBasePlugin) FileTree(org.gradle.api.file.FileTree) TaskProvider(org.gradle.api.tasks.TaskProvider) ProjectInternal(org.gradle.api.internal.project.ProjectInternal) COMMON_KIND(org.ehcache.build.plugins.VariantPlugin.COMMON_KIND) JavaBaseConvention(org.ehcache.build.conventions.JavaBaseConvention) DuplicatesStrategy(org.gradle.api.file.DuplicatesStrategy) OsgiManifestJarExtension(org.ehcache.build.util.OsgiManifestJarExtension) Zip(org.gradle.api.tasks.bundling.Zip) ShadowJar(com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar) RUNTIME_CLASSPATH_CONFIGURATION_NAME(org.gradle.api.plugins.JavaPlugin.RUNTIME_CLASSPATH_CONFIGURATION_NAME) Jvm(org.gradle.internal.jvm.Jvm) Project(org.gradle.api.Project) API_ELEMENTS_CONFIGURATION_NAME(org.gradle.api.plugins.JavaPlugin.API_ELEMENTS_CONFIGURATION_NAME) Optional(java.util.Optional) JvmPluginServices(org.gradle.api.plugins.jvm.internal.JvmPluginServices) ServiceRegistry(org.gradle.internal.service.ServiceRegistry) PluginUtils.kebab(org.ehcache.build.util.PluginUtils.kebab) RUNTIME_ELEMENTS_CONFIGURATION_NAME(org.gradle.api.plugins.JavaPlugin.RUNTIME_ELEMENTS_CONFIGURATION_NAME) PluginUtils.lower(org.ehcache.build.util.PluginUtils.lower) BasePlugin(org.gradle.api.plugins.BasePlugin) MavenPublication(org.gradle.api.publish.maven.MavenPublication) FileCollection(org.gradle.api.file.FileCollection) Configuration(org.gradle.api.artifacts.Configuration) LifecycleBasePlugin(org.gradle.language.base.plugins.LifecycleBasePlugin) Sync(org.gradle.api.tasks.Sync) BaseConvention(org.ehcache.build.conventions.BaseConvention) COMPILE_CLASSPATH_CONFIGURATION_NAME(org.gradle.api.plugins.JavaPlugin.COMPILE_CLASSPATH_CONFIGURATION_NAME) ConfigurationBucketSet(org.ehcache.build.util.ConfigurationBucketSet) Jar(org.gradle.api.tasks.bundling.Jar) JAVADOC(org.gradle.api.attributes.DocsType.JAVADOC) USER_MANUAL(org.gradle.api.attributes.DocsType.USER_MANUAL) Integer.parseInt(java.lang.Integer.parseInt) JAVADOC_ELEMENTS_CONFIGURATION_NAME(org.gradle.api.plugins.JavaPlugin.JAVADOC_ELEMENTS_CONFIGURATION_NAME) File(java.io.File) SoftwareComponentFactory(org.gradle.api.component.SoftwareComponentFactory) SOURCES_ELEMENTS_CONFIGURATION_NAME(org.gradle.api.plugins.JavaPlugin.SOURCES_ELEMENTS_CONFIGURATION_NAME) JavaEcosystemSupport.configureDefaultTargetPlatform(org.gradle.api.internal.artifacts.JavaEcosystemSupport.configureDefaultTargetPlatform) ArtifactResolveException(org.gradle.internal.resolve.ArtifactResolveException) Collections(java.util.Collections) Plugin(org.gradle.api.Plugin) OsgiManifestJarExtension(org.ehcache.build.util.OsgiManifestJarExtension) Configuration(org.gradle.api.artifacts.Configuration) ArtifactResolveException(org.gradle.internal.resolve.ArtifactResolveException) Optional(java.util.Optional) ShadowJar(com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar) ProjectInternal(org.gradle.api.internal.project.ProjectInternal) Javadoc(org.gradle.api.tasks.javadoc.Javadoc) FileCollection(org.gradle.api.file.FileCollection) JvmPluginServices(org.gradle.api.plugins.jvm.internal.JvmPluginServices) FileTree(org.gradle.api.file.FileTree) ShadowJar(com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar) Jar(org.gradle.api.tasks.bundling.Jar) ServiceRegistry(org.gradle.internal.service.ServiceRegistry) Sync(org.gradle.api.tasks.Sync) File(java.io.File) ConfigurationBucketSet(org.ehcache.build.util.ConfigurationBucketSet)

Aggregations

ShadowJar (com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar)1 File (java.io.File)1 Integer.parseInt (java.lang.Integer.parseInt)1 Collections (java.util.Collections)1 Optional (java.util.Optional)1 BaseConvention (org.ehcache.build.conventions.BaseConvention)1 BndConvention (org.ehcache.build.conventions.BndConvention)1 JavaBaseConvention (org.ehcache.build.conventions.JavaBaseConvention)1 COMMON_KIND (org.ehcache.build.plugins.VariantPlugin.COMMON_KIND)1 ConfigurationBucketSet (org.ehcache.build.util.ConfigurationBucketSet)1 OsgiManifestJarExtension (org.ehcache.build.util.OsgiManifestJarExtension)1 PluginUtils.camel (org.ehcache.build.util.PluginUtils.camel)1 PluginUtils.kebab (org.ehcache.build.util.PluginUtils.kebab)1 PluginUtils.lower (org.ehcache.build.util.PluginUtils.lower)1 Plugin (org.gradle.api.Plugin)1 Project (org.gradle.api.Project)1 Configuration (org.gradle.api.artifacts.Configuration)1 JAVADOC (org.gradle.api.attributes.DocsType.JAVADOC)1 SOURCES (org.gradle.api.attributes.DocsType.SOURCES)1 USER_MANUAL (org.gradle.api.attributes.DocsType.USER_MANUAL)1