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

The following examples show how to use org.gradle.api.tasks.bundling.Jar. These examples are extracted from open source projects. 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 Project: gradle-modules-plugin   Source File: CompileModuleInfoTask.java    License: 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 2
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 3
/**
 * 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 4
/**
 * 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 5
Source Project: playframework   Source File: PlayApplicationPlugin.java    License: 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 6
Source Project: gradle-plugins   Source File: WarAttachClassesPlugin.java    License: 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 7
Source Project: gradle-plugins   Source File: SourcesJarPlugin.java    License: 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 8
Source Project: app-gradle-plugin   Source File: SourceContextPlugin.java    License: 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 9
Source Project: shipkit   Source File: JavaLibraryPlugin.java    License: 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 10
Source Project: thorntail   Source File: ThorntailUtils.java    License: 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 11
Source Project: gradle-plugins   Source File: WarAttachClassesPlugin.java    License: 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 12
Source Project: gradle-plugins   Source File: SourcesJarPlugin.java    License: 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 13
Source Project: Pushjet-Android   Source File: JavaPlugin.java    License: 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 14
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 15
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 16
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 17
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 18
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 19
@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 20
Source Project: playframework   Source File: PlayPlugin.java    License: Apache License 2.0 5 votes vote down vote up
private static void configureJavaScriptTasks(Project project) {
    TaskProvider<JavaScriptMinify> javaScriptMinifyTask = project.getTasks().named(PlayJavaScriptPlugin.JS_MINIFY_TASK_NAME, JavaScriptMinify.class);

    project.getTasks().named(ASSEMBLE_TASK_NAME, task -> task.dependsOn(javaScriptMinifyTask));

    project.getTasks().named(PlayApplicationPlugin.ASSETS_JAR_TASK_NAME, Jar.class, task -> {
        task.dependsOn(javaScriptMinifyTask);
        task.from(javaScriptMinifyTask.get().getDestinationDir(), copySpec -> copySpec.into("public"));
    });
}
 
Example 21
Source Project: playframework   Source File: PlayApplicationPlugin.java    License: Apache License 2.0 5 votes vote down vote up
private TaskProvider<Jar> createAssetsJarTask(Project project) {
    TaskProvider<Jar> assetsJarTask = project.getTasks().register(ASSETS_JAR_TASK_NAME, Jar.class, jar -> {
        jar.setDescription("Assembles the assets jar for the application.");
        jar.setClassifier("assets");
        jar.from(project.file("public"), copySpec -> copySpec.into("public"));
    });

    project.getTasks().named(ASSEMBLE_TASK_NAME, assembleTask -> assembleTask.dependsOn(assetsJarTask));

    return assetsJarTask;
}
 
Example 22
Source Project: playframework   Source File: PlayApplicationPlugin.java    License: Apache License 2.0 5 votes vote down vote up
private void registerOutgoingArtifact(Project project, TaskProvider<Jar> assetsJarTask) {
    Configuration runtimeElementsConfiguration = project.getConfigurations().getByName(RUNTIME_ELEMENTS_CONFIGURATION_NAME);
    PublishArtifact jarArtifact = new LazyPublishArtifact(assetsJarTask);
    ConfigurationPublications publications = runtimeElementsConfiguration.getOutgoing();
    publications.getArtifacts().add(jarArtifact);
    publications.getAttributes().attribute(ArtifactAttributes.ARTIFACT_FORMAT, ArtifactTypeDefinition.JAR_TYPE);
}
 
Example 23
Source Project: playframework   Source File: PlayApplicationPlugin.java    License: Apache License 2.0 5 votes vote down vote up
private TaskProvider<PlayRun> createRunTask(Project project, PlayExtension playExtension, TaskProvider<Jar> mainJarTask, TaskProvider<Jar> assetsJarTask) {
    return project.getTasks().register("runPlay", PlayRun.class, playRun -> {
        playRun.setDescription("Runs the Play application for local development.");
        playRun.setGroup("Run");
        playRun.getWorkingDir().convention(project.getLayout().getProjectDirectory());
        playRun.getPlatform().convention(project.provider(() -> playExtension.getPlatform()));
        playRun.getApplicationJar().convention(mainJarTask.get().getArchiveFile());
        playRun.getAssetsJar().convention(assetsJarTask.get().getArchiveFile());
        playRun.getAssetsDirs().from(project.file("public"));
    });
}
 
Example 24
Source Project: gradle-plugins   Source File: WarArchiveClassesPlugin.java    License: 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 25
Source Project: gradle-plugins   Source File: MavenPublishBasePlugin.java    License: 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 Project: gradle-plugins   Source File: JavadocJarPlugin.java    License: 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 27
@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 28
Source Project: wildfly-swarm   Source File: PackagePlugin.java    License: 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 29
Source Project: shipkit   Source File: ComparePublicationsTask.java    License: 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 30
Source Project: shipkit   Source File: JavaPublishPlugin.java    License: 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);
}