org.gradle.api.tasks.bundling.Jar Java Examples

The following examples show how to use org.gradle.api.tasks.bundling.Jar. 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 vote down vote up
@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: JavaLibraryPlugin.java    From shipkit with MIT License 6 votes vote down vote up
@Override
public void apply(final Project project) {
    project.getPlugins().apply("java");

    final CopySpec license = project.copySpec(copy -> copy.from(project.getRootDir()).include("LICENSE"));

    ((Jar) project.getTasks().getByName("jar")).with(license);

    final Jar sourcesJar = project.getTasks().create(SOURCES_JAR_TASK, Jar.class, jar -> {
        jar.from(JavaPluginUtil.getMainSourceSet(project).getAllSource());
        jar.setClassifier("sources");
        jar.with(license);
    });

    final Task javadocJar = project.getTasks().create(JAVADOC_JAR_TASK, Jar.class, jar -> {
        jar.from(project.getTasks().getByName("javadoc"));
        jar.setClassifier("javadoc");
        jar.with(license);
    });

    project.getArtifacts().add("archives", sourcesJar);
    project.getArtifacts().add("archives", javadocJar);
}
 
Example #3
Source File: SourceContextPlugin.java    From app-gradle-plugin with Apache License 2.0 6 votes vote down vote up
private void createSourceContextTask() {
  project
      .getTasks()
      .create(
          "_createSourceContext",
          GenRepoInfoFileTask.class,
          genRepoInfoFile -> {
            genRepoInfoFile.setDescription("_internal");

            project.afterEvaluate(
                project -> {
                  genRepoInfoFile.setConfiguration(extension);
                  genRepoInfoFile.setGcloud(cloudSdkOperations.getGcloud());
                });
          });
  configureArchiveTask(project.getTasks().withType(War.class).findByName("war"));
  configureArchiveTask(project.getTasks().withType(Jar.class).findByName("jar"));
}
 
Example #4
Source File: SourcesJarPlugin.java    From gradle-plugins with MIT License 6 votes vote down vote up
@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 #5
Source File: WarAttachClassesPlugin.java    From gradle-plugins with MIT License 6 votes vote down vote up
@Override
public void apply(Project project) {
    project.getPlugins().apply(WarPlugin.class);

    WarAttachClassesConvention attachClassesConvention = new WarAttachClassesConvention();

    project.getTasks().named(WarPlugin.WAR_TASK_NAME, War.class, war ->
            war.getConvention().getPlugins().put("attachClasses", attachClassesConvention)
    );

    project.afterEvaluate(p -> {
        if (attachClassesConvention.isAttachClasses()) {
            TaskProvider<Jar> jar = project.getTasks().named(JavaPlugin.JAR_TASK_NAME, Jar.class, j ->
                    j.getArchiveClassifier().convention(attachClassesConvention.getClassesClassifier())
            );

            project.getArtifacts().add(Dependency.ARCHIVES_CONFIGURATION, jar);
        }
    });
}
 
Example #6
Source File: CompileModuleInfoTask.java    From gradle-modules-plugin with MIT License 6 votes vote down vote up
/**
 * @see CompileTask#configureModularityForCompileJava
 */
void configureModularityForCompileModuleInfoJava(
        JavaCompile compileJava, CompileModuleOptions moduleOptions) {
    JavaCompile compileModuleInfoJava = preconfigureCompileModuleInfoJava(compileJava);
    CompileModuleInfoHelper.dependOnOtherCompileModuleInfoJavaTasks(compileModuleInfoJava);

    CompileJavaTaskMutator mutator = createCompileJavaTaskMutator(compileJava, moduleOptions);

    // don't convert to lambda: https://github.com/java9-modularity/gradle-modules-plugin/issues/54
    compileModuleInfoJava.doFirst(new Action<Task>() {
        @Override
        public void execute(Task task) {
            mutator.modularizeJavaCompileTask(compileModuleInfoJava);
        }
    });

    project.getTasks().withType(Jar.class).configureEach(jar -> jar.from(helper().getModuleInfoDir()));
}
 
Example #7
Source File: PlayApplicationPlugin.java    From playframework with Apache License 2.0 6 votes vote down vote up
@Override
public void apply(Project project) {
    project.getPluginManager().apply(ScalaPlugin.class);

    PlayExtension playExtension = project.getExtensions().create(PLAY_EXTENSION_NAME, PlayExtension.class, project.getObjects());
    Configuration playConfiguration = project.getConfigurations().create(PLATFORM_CONFIGURATION);
    project.getConfigurations().getByName(COMPILE_CLASSPATH_CONFIGURATION_NAME).extendsFrom(playConfiguration);

    applyPlayPlugins(project);

    configureJavaAndScalaSourceSet(project);
    TaskProvider<Jar> mainJarTask = project.getTasks().named(JAR_TASK_NAME, Jar.class);
    TaskProvider<Jar> assetsJarTask = createAssetsJarTask(project);
    registerOutgoingArtifact(project, assetsJarTask);
    TaskProvider<PlayRun> playRun = createRunTask(project, playExtension, mainJarTask, assetsJarTask);

    project.afterEvaluate(project1 -> {
        PlayPlatform playPlatform = playExtension.getPlatform();
        failIfInjectedRouterIsUsedWithOldVersion(playExtension.getInjectedRoutesGenerator().get(), playPlatform);
        addAutomaticDependencies(project.getDependencies(), playPlatform);
        configureRunTask(playRun, filtered(project.getConfigurations().getByName(RUNTIME_CLASSPATH_CONFIGURATION_NAME)));
    });
}
 
Example #8
Source File: JavaPlugin.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private void configureArchivesAndComponent(final Project project, final JavaPluginConvention pluginConvention) {
    Jar jar = project.getTasks().create(JAR_TASK_NAME, Jar.class);
    jar.getManifest().from(pluginConvention.getManifest());
    jar.setDescription("Assembles a jar archive containing the main classes.");
    jar.setGroup(BasePlugin.BUILD_GROUP);
    jar.from(pluginConvention.getSourceSets().getByName(SourceSet.MAIN_SOURCE_SET_NAME).getOutput());
    jar.getMetaInf().from(new Callable() {
        public Object call() throws Exception {
            return pluginConvention.getMetaInf();
        }
    });

    ArchivePublishArtifact jarArtifact = new ArchivePublishArtifact(jar);
    Configuration runtimeConfiguration = project.getConfigurations().getByName(RUNTIME_CONFIGURATION_NAME);

    runtimeConfiguration.getArtifacts().add(jarArtifact);
    project.getExtensions().getByType(DefaultArtifactPublicationSet.class).addCandidate(jarArtifact);
    project.getComponents().add(new JavaLibrary(jarArtifact, runtimeConfiguration.getAllDependencies()));
}
 
Example #9
Source File: ShadedJarPackaging.java    From transport with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/**
 * Creates a {@link ShadeTask} which generates a shaded JAR containing all runtime dependencies of the platform's
 * {@link SourceSet}
 *
 * TODO: This code is borrowed from the Shade plugin. Call the functionality residing in the Shade plugin once it is
 * available
 */
private TaskProvider<ShadeTask> createShadeTask(Project project, Platform platform, SourceSet sourceSet,
    SourceSet mainSourceSet) {
  TaskProvider<ShadeTask> shadeTask =
      project.getTasks().register(sourceSet.getTaskName("shade", "Jar"), ShadeTask.class, task -> {
        task.setGroup(ShadowJavaPlugin.getSHADOW_GROUP());
        task.setDescription("Create a combined JAR of " + platform.getName() + " output and runtime dependencies");
        task.setClassifier(platform.getName());
        task.getManifest()
            .inheritFrom(project.getTasks().named(mainSourceSet.getJarTaskName(), Jar.class).get().getManifest());
        task.from(sourceSet.getOutput());
        task.setConfigurations(ImmutableList.of(getConfigurationForSourceSet(project, sourceSet, RUNTIME_CLASSPATH)));
        task.exclude("META-INF/INDEX.LIST", "META-INF/*.SF", "META-INF/*.DSA", "META-INF/*.RSA");
      });

  // TODO: Figure out why this artifact is generated but not being published in Maven
  project.getArtifacts().add(ShadowBasePlugin.getCONFIGURATION_NAME(), shadeTask);
  return shadeTask;
}
 
Example #10
Source File: DistributionPackaging.java    From transport with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/**
 * Creates a thin JAR for the platform's {@link SourceSet} to be included in the distribution
 */
private TaskProvider<Jar> createThinJarTask(Project project, SourceSet sourceSet, String platformName) {
    /*
      task <platformName>ThinJar(type: Jar, dependsOn: prestoClasses) {
        classifier 'platformName'
        from sourceSets.<platform>.output
        from sourceSets.<platform>.resources
      }
    */

  return project.getTasks().register(sourceSet.getTaskName(null, "thinJar"), Jar.class, task -> {
    task.dependsOn(project.getTasks().named(sourceSet.getClassesTaskName()));
    task.setDescription("Assembles a thin jar archive containing the " + platformName
        + " classes to be included in the distribution");
    task.setClassifier(platformName + "Thin");
    task.from(sourceSet.getOutput());
    task.from(sourceSet.getResources());
  });
}
 
Example #11
Source File: JavaPlugin.java    From pushfish-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private void configureArchivesAndComponent(final Project project, final JavaPluginConvention pluginConvention) {
    Jar jar = project.getTasks().create(JAR_TASK_NAME, Jar.class);
    jar.getManifest().from(pluginConvention.getManifest());
    jar.setDescription("Assembles a jar archive containing the main classes.");
    jar.setGroup(BasePlugin.BUILD_GROUP);
    jar.from(pluginConvention.getSourceSets().getByName(SourceSet.MAIN_SOURCE_SET_NAME).getOutput());
    jar.getMetaInf().from(new Callable() {
        public Object call() throws Exception {
            return pluginConvention.getMetaInf();
        }
    });

    ArchivePublishArtifact jarArtifact = new ArchivePublishArtifact(jar);
    Configuration runtimeConfiguration = project.getConfigurations().getByName(RUNTIME_CONFIGURATION_NAME);

    runtimeConfiguration.getArtifacts().add(jarArtifact);
    project.getExtensions().getByType(DefaultArtifactPublicationSet.class).addCandidate(jarArtifact);
    project.getComponents().add(new JavaLibrary(jarArtifact, runtimeConfiguration.getAllDependencies()));
}
 
Example #12
Source File: ThorntailUtils.java    From thorntail with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the most suitable Archive-Task for wrapping in the swarm jar - in the following order:
 * <p>
 * 1. Custom-JAR-Task defined in ThorntailExtension 'archiveTask'
 * 2. WAR-Task
 * 3. JAR-Task
 */
public static Jar getArchiveTask(Project project) {

    TaskCollection<Jar> existingArchiveTasks = project.getTasks().withType(Jar.class);
    Jar customArchiveTask = project.getExtensions().getByType(ThorntailExtension.class).getArchiveTask();

    if (customArchiveTask != null) {
        return existingArchiveTasks.getByName(customArchiveTask.getName());

    } else if (existingArchiveTasks.findByName(WarPlugin.WAR_TASK_NAME) != null) {
        return existingArchiveTasks.getByName(WarPlugin.WAR_TASK_NAME);

    } else if (existingArchiveTasks.findByName(JavaPlugin.JAR_TASK_NAME) != null) {
        return existingArchiveTasks.getByName(JavaPlugin.JAR_TASK_NAME);
    }

    throw new GradleException("Unable to detect Archive-Task: project contains neither 'war' nor 'jar', " +
            "nor is custom Archive-Task specified in the \"thorntail\" extension.");
}
 
Example #13
Source File: WarAttachClassesPlugin.java    From gradle-plugins with MIT License 6 votes vote down vote up
@Override
public void apply(Project project) {
    project.getPlugins().apply(WarPlugin.class);

    WarAttachClassesConvention attachClassesConvention = new WarAttachClassesConvention();

    project.getTasks().named(WarPlugin.WAR_TASK_NAME, War.class, war ->
            war.getConvention().getPlugins().put("attachClasses", attachClassesConvention)
    );

    project.afterEvaluate(p -> {
        if (attachClassesConvention.isAttachClasses()) {
            TaskProvider<Jar> jar = project.getTasks().named(JavaPlugin.JAR_TASK_NAME, Jar.class, j ->
                    j.getArchiveClassifier().convention(attachClassesConvention.getClassesClassifier())
            );

            project.getArtifacts().add(Dependency.ARCHIVES_CONFIGURATION, jar);
        }
    });
}
 
Example #14
Source File: JavaPublishPlugin.java    From shipkit with MIT License 5 votes vote down vote up
public void apply(final Project project) {
    final ShipkitConfiguration conf = project.getPlugins().apply(ShipkitConfigurationPlugin.class).getConfiguration();

    project.getPlugins().apply(LocalSnapshotPlugin.class);
    Task snapshotTask = project.getTasks().getByName(LocalSnapshotPlugin.SNAPSHOT_TASK);
    snapshotTask.dependsOn(MAVEN_LOCAL_TASK);

    project.getPlugins().apply(JavaLibraryPlugin.class);
    project.getPlugins().apply("maven-publish");

    final Jar sourcesJar = (Jar) project.getTasks().getByName(JavaLibraryPlugin.SOURCES_JAR_TASK);
    final Jar javadocJar = (Jar) project.getTasks().getByName(JavaLibraryPlugin.JAVADOC_JAR_TASK);

    GradleDSLHelper.publications(project, publications -> {
        MavenPublication p = publications.create(PUBLICATION_NAME, MavenPublication.class, publication -> {
            publication.from(project.getComponents().getByName("java"));
            publication.artifact(sourcesJar);
            publication.artifact(javadocJar);
            DeferredConfiguration.deferredConfiguration(project, () -> {
                publication.setArtifactId(((Jar) project.getTasks().getByName("jar")).getBaseName());
            });
            PomCustomizer.customizePom(project, conf, publication);
        });
        LOG.info("{} - configured '{}' publication", project.getPath(), p.getArtifactId());
    });

    //so that we flesh out problems with maven publication during the build process
    project.getTasks().getByName("build").dependsOn(MAVEN_LOCAL_TASK);
}
 
Example #15
Source File: MavenPublishBasePlugin.java    From gradle-plugins with MIT License 5 votes vote down vote up
@Override
public void apply(Project project) {
    this.project = project;
    project.getPlugins().apply(getPluginClass());
    project.getPlugins().apply(MavenPublishPlugin.class);

    publication = project.getExtensions().getByType(PublishingExtension.class)
            .getPublications()
            .create(getPublicationName(), MavenPublication.class);

    project.afterEvaluate(p -> {
        publication.from(getSoftwareComponent());

        project.getPlugins().withType(SourcesJarPlugin.class, sourcesJarPlugin -> {
            Jar sourcesJar = sourcesJarPlugin.getSourcesJar().get();
            publication.artifact(sourcesJar);
        });

        project.getPlugins().withType(JavadocJarPlugin.class, javadocJarPlugin -> {
            Jar javadocJar = javadocJarPlugin.getJavadocJar().get();
            publication.artifact(javadocJar);
        });

        project.getPlugins().withType(SigningPlugin.class, signingPlugin -> project.getExtensions()
                .getByType(SigningExtension.class)
                .sign(publication)
        );
    });
}
 
Example #16
Source File: JavadocJarPlugin.java    From gradle-plugins with MIT License 5 votes vote down vote up
@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"
                ));
            });
        });

    });
}
 
Example #17
Source File: PackagePlugin.java    From thorntail with Apache License 2.0 5 votes vote down vote up
@Override
public void apply(Project project) {
    super.apply(project);
    PluginManager pluginManager = project.getPluginManager();
    if (!pluginManager.hasPlugin(ThorntailArquillianPlugin.PLUGIN_ID)) {
        pluginManager.apply(ThorntailArquillianPlugin.class);
    }
    project.afterEvaluate(__ -> {
        final TaskContainer tasks = project.getTasks();
        final PackageTask packageTask = tasks.create(THORNTAIL_PACKAGE_TASK_NAME, PackageTask.class);

        final Jar archiveTask = ThorntailUtils.getArchiveTask(project);
        packageTask.jarTask(archiveTask).dependsOn(archiveTask);

        tasks.getByName(JavaBasePlugin.BUILD_TASK_NAME).dependsOn(packageTask);

        Task classesTask = tasks.getByName(JavaPlugin.CLASSES_TASK_NAME);

        StartTask runTask = tasks.create(THORNTAIL_RUN_TASK_NAME, StartTask.class, StartTask::waitForProcess);
        runTask.dependsOn(classesTask);

        StartTask startTask = tasks.create(THORNTAIL_START_TASK_NAME, StartTask.class);
        startTask.dependsOn(classesTask);

        tasks.create(THORNTAIL_STOP_TASK_NAME, StopTask.class);
    });
}
 
Example #18
Source File: JvmComponentPlugin.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private Task createJarTask(TaskContainer tasks, JarBinarySpecInternal binary) {
    Jar jar = tasks.create(binary.getNamingScheme().getTaskName("create"), Jar.class);
    jar.setDescription(String.format("Creates the binary file for %s.", binary.getNamingScheme().getDescription()));
    jar.from(binary.getClassesDir());
    jar.from(binary.getResourcesDir());

    jar.setDestinationDir(binary.getJarFile().getParentFile());
    jar.setArchiveName(binary.getJarFile().getName());

    return jar;
}
 
Example #19
Source File: ComparePublicationsTask.java    From shipkit with MIT License 5 votes vote down vote up
/**
 * Sets the sourcesJar for comparision with {@link #getPreviousSourcesJar()}.
 * Task dependency will be automatically added from this task to sourcesJar task supplied as parameter.
 * During comparison, the algorithm will read jar's output file using {@link Jar#getArchivePath()}.
 */
public void compareSourcesJar(Jar sourcesJar) {
    //when we compare, we can get the sources jar file via sourcesJar.archivePath
    this.sourcesJar = sourcesJar;

    //so that when we compare jars, the local sources jar is already built.
    this.dependsOn(sourcesJar);
}
 
Example #20
Source File: PackagePlugin.java    From wildfly-swarm with Apache License 2.0 5 votes vote down vote up
@Override
public void apply(Project project) {
    project.getExtensions().create("swarm", SwarmExtension.class);
    project.afterEvaluate(__ -> {
        final TaskContainer tasks = project.getTasks();
        final PackageTask packageTask = tasks.create("wildfly-swarm-package", PackageTask.class);
        tasks.withType(Jar.class, task -> packageTask.jarTask(task).dependsOn(task));
        tasks.getByName("build").dependsOn(packageTask);
    });
}
 
Example #21
Source File: JavaGradlePluginPlugin.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private void configureJarTask(Project project) {
    Jar jarTask = (Jar) project.getTasks().findByName(JAR_TASK);
    List<PluginDescriptor> descriptors = new ArrayList<PluginDescriptor>();
    Set<String> classList = new HashSet<String>();
    PluginDescriptorCollectorAction pluginDescriptorCollector = new PluginDescriptorCollectorAction(descriptors);
    ClassManifestCollectorAction classManifestCollector = new ClassManifestCollectorAction(classList);
    PluginValidationAction pluginValidationAction = new PluginValidationAction(descriptors, classList);

    jarTask.filesMatching(PLUGIN_DESCRIPTOR_PATTERN, pluginDescriptorCollector);
    jarTask.filesMatching(CLASSES_PATTERN, classManifestCollector);
    jarTask.doLast(pluginValidationAction);
}
 
Example #22
Source File: WarArchiveClassesPlugin.java    From gradle-plugins with MIT License 5 votes vote down vote up
@Override
public void apply(Project project) {

    project.getTasks().withType(War.class, war -> {

        WarArchiveClassesConvention archiveClassesConvention = new WarArchiveClassesConvention();

        war.getConvention().getPlugins().put("archiveClasses", archiveClassesConvention);

        Jar warClassesJar = project.getTasks().create(war.getName() + "ClassesJar", Jar.class);
        warClassesJar.getArchiveBaseName().convention(war.getArchiveBaseName());
        warClassesJar.getArchiveAppendix().convention(war.getArchiveAppendix());
        warClassesJar.getArchiveVersion().convention(war.getArchiveVersion());
        warClassesJar.getArchiveClassifier().convention(war.getArchiveClassifier());

        project.afterEvaluate(p -> {

            warClassesJar.setEnabled(archiveClassesConvention.isArchiveClasses());

            if (archiveClassesConvention.isArchiveClasses()) {
                FileCollection warClasspath = war.getClasspath();

                warClassesJar.from(warClasspath != null ? warClasspath.filter(File::isDirectory) : Collections.emptyList());

                war.setClasspath(warClasspath == null ? null : warClasspath.filter(File::isFile).plus(project.files(warClassesJar)));
            }
        });
    });
}
 
Example #23
Source File: AppEngineAppYamlPluginTest.java    From app-gradle-plugin with Apache License 2.0 5 votes vote down vote up
@Test
public void testDefaultConfigurationAlternative() {
  Project p =
      new TestProject(testProjectDir.getRoot()).addDockerDir().applyAppYamlProjectBuilder();

  AppEngineAppYamlExtension ext = p.getExtensions().getByType(AppEngineAppYamlExtension.class);
  StageAppYamlExtension stageExt = ext.getStage();

  assertTrue(new File(testProjectDir.getRoot(), "src/main/docker").exists());
  assertEquals((((Jar) p.getProperties().get("jar")).getArchivePath()), stageExt.getArtifact());
}
 
Example #24
Source File: JavaPlugin.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private void configureArchivesAndComponent(final Project project, final JavaPluginConvention pluginConvention) {
    Jar jar = project.getTasks().create(JAR_TASK_NAME, Jar.class);
    jar.setDescription("Assembles a jar archive containing the main classes.");
    jar.setGroup(BasePlugin.BUILD_GROUP);
    jar.from(pluginConvention.getSourceSets().getByName(SourceSet.MAIN_SOURCE_SET_NAME).getOutput());

    ArchivePublishArtifact jarArtifact = new ArchivePublishArtifact(jar);
    Configuration runtimeConfiguration = project.getConfigurations().getByName(RUNTIME_CONFIGURATION_NAME);

    runtimeConfiguration.getArtifacts().add(jarArtifact);
    project.getExtensions().getByType(DefaultArtifactPublicationSet.class).addCandidate(jarArtifact);
    project.getComponents().add(new JavaLibrary(jarArtifact, runtimeConfiguration.getAllDependencies()));
}
 
Example #25
Source File: MavenPublishBasePlugin.java    From gradle-plugins with MIT License 5 votes vote down vote up
@Override
public void apply(Project project) {
    this.project = project;
    project.getPlugins().apply(getPluginClass());
    project.getPlugins().apply(MavenPublishPlugin.class);

    publication = project.getExtensions().getByType(PublishingExtension.class)
            .getPublications()
            .create(getPublicationName(), MavenPublication.class);

    project.afterEvaluate(p -> {
        publication.from(getSoftwareComponent());

        project.getPlugins().withType(SourcesJarPlugin.class, sourcesJarPlugin -> {
            Jar sourcesJar = sourcesJarPlugin.getSourcesJar().get();
            publication.artifact(sourcesJar);
        });

        project.getPlugins().withType(JavadocJarPlugin.class, javadocJarPlugin -> {
            Jar javadocJar = javadocJarPlugin.getJavadocJar().get();
            publication.artifact(javadocJar);
        });

        project.getPlugins().withType(SigningPlugin.class, signingPlugin -> project.getExtensions()
                .getByType(SigningExtension.class)
                .sign(publication)
        );
    });
}
 
Example #26
Source File: DistributionPackaging.java    From transport with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public List<TaskProvider<? extends Task>> configurePackagingTasks(Project project, Platform platform,
    SourceSet platformSourceSet, SourceSet mainSourceSet) {
  // Create a thin JAR to be included in the distribution
  final TaskProvider<Jar> platformThinJarTask = createThinJarTask(project, platformSourceSet, platform.getName());

  /*
    Include the thin JAR and all the runtime dependencies into the distribution for a given platform

    distributions {
      <platformName> {
        contents {
          from <platformThinJarTask>
          from project.configurations.<platformRuntimeClasspath>
        }
      }
    }
   */
  DistributionContainer distributions = project.getExtensions().getByType(DistributionContainer.class);
  distributions.register(platform.getName(), distribution -> {
    distribution.setBaseName(project.getName());
    distribution.getContents()
        .from(platformThinJarTask)
        .from(getConfigurationForSourceSet(project, platformSourceSet, RUNTIME_CLASSPATH));
  });

  // Explicitly set classifiers for the created distributions or else leads to Maven packaging issues due to multiple
  // artifacts with the same classifier
  project.getTasks().named(platform.getName() + "DistTar", Tar.class, tar -> tar.setClassifier(platform.getName()));
  project.getTasks().named(platform.getName() + "DistZip", Zip.class, zip -> zip.setClassifier(platform.getName()));
  return ImmutableList.of(project.getTasks().named(platform.getName() + "DistTar", Tar.class),
      project.getTasks().named(platform.getName() + "DistZip", Zip.class));
}
 
Example #27
Source File: PackagePlugin.java    From ARCHIVE-wildfly-swarm with Apache License 2.0 5 votes vote down vote up
@Override
public void apply(Project project) {
    project.getExtensions().create("swarm", SwarmExtension.class);
    project.afterEvaluate(__ -> {
        final TaskContainer tasks = project.getTasks();
        final PackageTask packageTask = tasks.create("wildfly-swarm-package", PackageTask.class);
        tasks.withType(Jar.class, task -> packageTask.jarTask(task).dependsOn(task));
        tasks.getByName("build").dependsOn(packageTask);
    });
}
 
Example #28
Source File: BasePlugin.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private void configureArchiveDefaults(final Project project, final BasePluginConvention pluginConvention) {
    project.getTasks().withType(AbstractArchiveTask.class, new Action<AbstractArchiveTask>() {
        public void execute(AbstractArchiveTask task) {
            ConventionMapping taskConventionMapping = task.getConventionMapping();

            Callable<File> destinationDir;
            if (task instanceof Jar) {
                destinationDir = new Callable<File>() {
                    public File call() throws Exception {
                        return pluginConvention.getLibsDir();
                    }
                };
            } else {
                destinationDir = new Callable<File>() {
                    public File call() throws Exception {
                        return pluginConvention.getDistsDir();
                    }
                };
            }
            taskConventionMapping.map("destinationDir", destinationDir);

            taskConventionMapping.map("version", new Callable<String>() {
                public String call() throws Exception {
                    return project.getVersion() == Project.DEFAULT_VERSION ? null : project.getVersion().toString();
                }
            });

            taskConventionMapping.map("baseName", new Callable<String>() {
                public String call() throws Exception {
                    return pluginConvention.getArchivesBaseName();
                }
            });
        }
    });
}
 
Example #29
Source File: JvmComponentPlugin.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private Task createJarTask(TaskContainer tasks, JarBinarySpecInternal binary) {
    Jar jar = tasks.create(binary.getNamingScheme().getTaskName("create"), Jar.class);
    jar.setDescription(String.format("Creates the binary file for %s.", binary.getNamingScheme().getDescription()));
    jar.from(binary.getClassesDir());
    jar.from(binary.getResourcesDir());

    jar.setDestinationDir(binary.getJarFile().getParentFile());
    jar.setArchiveName(binary.getJarFile().getName());

    return jar;
}
 
Example #30
Source File: JavaGradlePluginPlugin.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private void configureJarTask(Project project) {
    Jar jarTask = (Jar) project.getTasks().findByName(JAR_TASK);
    List<PluginDescriptor> descriptors = new ArrayList<PluginDescriptor>();
    Set<String> classList = new HashSet<String>();
    PluginDescriptorCollectorAction pluginDescriptorCollector = new PluginDescriptorCollectorAction(descriptors);
    ClassManifestCollectorAction classManifestCollector = new ClassManifestCollectorAction(classList);
    PluginValidationAction pluginValidationAction = new PluginValidationAction(descriptors, classList);

    jarTask.filesMatching(PLUGIN_DESCRIPTOR_PATTERN, pluginDescriptorCollector);
    jarTask.filesMatching(CLASSES_PATTERN, classManifestCollector);
    jarTask.doLast(pluginValidationAction);
}