private void configureConfigurations(final Project project) { ConfigurationContainer configurations = project.getConfigurations(); project.setProperty("status", "integration"); Configuration archivesConfiguration = configurations.maybeCreate(Dependency.ARCHIVES_CONFIGURATION). setDescription("Configuration for archive artifacts."); configurations.maybeCreate(Dependency.DEFAULT_CONFIGURATION). setDescription("Configuration for default artifacts."); final DefaultArtifactPublicationSet defaultArtifacts = project.getExtensions().create( "defaultArtifacts", DefaultArtifactPublicationSet.class, archivesConfiguration.getArtifacts() ); configurations.all(new Action<Configuration>() { public void execute(Configuration configuration) { configuration.getArtifacts().all(new Action<PublishArtifact>() { public void execute(PublishArtifact artifact) { defaultArtifacts.addCandidate(artifact); } }); } }); }
private void configureConfigurations(final Project project) { ConfigurationContainer configurations = project.getConfigurations(); project.setProperty("status", "integration"); Configuration archivesConfiguration = configurations.create(Dependency.ARCHIVES_CONFIGURATION). setDescription("Configuration for archive artifacts."); configurations.create(Dependency.DEFAULT_CONFIGURATION). setDescription("Configuration for default artifacts."); final DefaultArtifactPublicationSet defaultArtifacts = project.getExtensions().create( "defaultArtifacts", DefaultArtifactPublicationSet.class, archivesConfiguration.getArtifacts() ); configurations.all(new Action<Configuration>() { public void execute(Configuration configuration) { configuration.getArtifacts().all(new Action<PublishArtifact>() { public void execute(PublishArtifact artifact) { defaultArtifacts.addCandidate(artifact); } }); } }); }
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())); }
private void setupEarTask(final Project project, EarPluginConvention convention) { Ear ear = project.getTasks().create(EAR_TASK_NAME, Ear.class); ear.setDescription("Generates a ear archive with all the modules, the application descriptor and the libraries."); DeploymentDescriptor deploymentDescriptor = convention.getDeploymentDescriptor(); if (deploymentDescriptor != null) { if (deploymentDescriptor.getDisplayName() == null) { deploymentDescriptor.setDisplayName(project.getName()); } if (deploymentDescriptor.getDescription() == null) { deploymentDescriptor.setDescription(project.getDescription()); } } ear.setGroup(BasePlugin.BUILD_GROUP); project.getExtensions().getByType(DefaultArtifactPublicationSet.class).addCandidate(new ArchivePublishArtifact(ear)); project.getTasks().withType(Ear.class, new Action<Ear>() { public void execute(Ear task) { task.getLib().from(new Callable<FileCollection>() { public FileCollection call() throws Exception { return project.getConfigurations().getByName(EARLIB_CONFIGURATION_NAME); } }); task.from(new Callable<FileCollection>() { public FileCollection call() throws Exception { // add the module configuration's files return project.getConfigurations().getByName(DEPLOY_CONFIGURATION_NAME); } }); } }); }
private <T extends AbstractArchiveTask> Task configureArchiveTask(Project project, String taskName, final Distribution distribution, Class<T> type) { final T archiveTask = project.getTasks().create(taskName, type); archiveTask.setDescription("Bundles the project as a distribution."); archiveTask.setGroup(DISTRIBUTION_GROUP); archiveTask.getConventionMapping().map("baseName", new Callable<Object>() { @Override public Object call() throws Exception { if (distribution.getBaseName() == null || distribution.getBaseName().equals("")) { throw new GradleException("Distribution baseName must not be null or empty! Check your configuration of the distribution plugin."); } return distribution.getBaseName(); } }); Callable<String> baseDir = new Callable<String>() { @Override public String call() throws Exception { // For backwards compatibility, we need to simulate the exact behaviour of the previously uses Groovy minus operator String toBeRenamedIfExists = "." + archiveTask.getExtension(); return archiveTask.getArchiveName().replaceFirst(toBeRenamedIfExists, ""); } }; CopySpec childSpec = project.copySpec(); childSpec.into(baseDir); childSpec.with(distribution.getContents()); archiveTask.with(childSpec); ArchivePublishArtifact archiveArtifact = new ArchivePublishArtifact(archiveTask); project.getExtensions().getByType(DefaultArtifactPublicationSet.class).addCandidate(archiveArtifact); return archiveTask; }
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())); }
public void apply(final Project project) { project.getPluginManager().apply(JavaPlugin.class); final WarPluginConvention pluginConvention = new WarPluginConvention(project); project.getConvention().getPlugins().put("war", pluginConvention); project.getTasks().withType(War.class, new Action<War>() { public void execute(War task) { task.from(new Callable() { public Object call() throws Exception { return pluginConvention.getWebAppDir(); } }); task.dependsOn(new Callable() { public Object call() throws Exception { return project.getConvention().getPlugin(JavaPluginConvention.class).getSourceSets().getByName( SourceSet.MAIN_SOURCE_SET_NAME).getRuntimeClasspath(); } }); task.classpath(new Object[] {new Callable() { public Object call() throws Exception { FileCollection runtimeClasspath = project.getConvention().getPlugin(JavaPluginConvention.class) .getSourceSets().getByName(SourceSet.MAIN_SOURCE_SET_NAME).getRuntimeClasspath(); Configuration providedRuntime = project.getConfigurations().getByName( PROVIDED_RUNTIME_CONFIGURATION_NAME); return runtimeClasspath.minus(providedRuntime); } }}); } }); War war = project.getTasks().create(WAR_TASK_NAME, War.class); war.setDescription("Generates a war archive with all the compiled classes, the web-app content and the libraries."); war.setGroup(BasePlugin.BUILD_GROUP); ArchivePublishArtifact warArtifact = new ArchivePublishArtifact(war); project.getExtensions().getByType(DefaultArtifactPublicationSet.class).addCandidate(warArtifact); configureConfigurations(project.getConfigurations()); configureComponent(project, warArtifact); }
public void apply(final Project project) { project.getPlugins().apply(JavaPlugin.class); final WarPluginConvention pluginConvention = new WarPluginConvention(project); project.getConvention().getPlugins().put("war", pluginConvention); project.getTasks().withType(War.class, new Action<War>() { public void execute(War task) { task.from(new Callable() { public Object call() throws Exception { return pluginConvention.getWebAppDir(); } }); task.dependsOn(new Callable() { public Object call() throws Exception { return project.getConvention().getPlugin(JavaPluginConvention.class).getSourceSets().getByName( SourceSet.MAIN_SOURCE_SET_NAME).getRuntimeClasspath(); } }); task.classpath(new Object[] {new Callable() { public Object call() throws Exception { FileCollection runtimeClasspath = project.getConvention().getPlugin(JavaPluginConvention.class) .getSourceSets().getByName(SourceSet.MAIN_SOURCE_SET_NAME).getRuntimeClasspath(); Configuration providedRuntime = project.getConfigurations().getByName( PROVIDED_RUNTIME_CONFIGURATION_NAME); return runtimeClasspath.minus(providedRuntime); } }}); } }); War war = project.getTasks().create(WAR_TASK_NAME, War.class); war.setDescription("Generates a war archive with all the compiled classes, the web-app content and the libraries."); war.setGroup(BasePlugin.BUILD_GROUP); ArchivePublishArtifact warArtifact = new ArchivePublishArtifact(war); project.getExtensions().getByType(DefaultArtifactPublicationSet.class).addCandidate(warArtifact); configureConfigurations(project.getConfigurations()); configureComponent(project, warArtifact); }
/** * Setup the NW EAR Task. * Uses some magic to set up the default archive conventions, using the same name as the task (nwear). * For example nwear.archiveName = '' */ private NWEar setupEarTask(final Project project, NWEarPluginConvention convention) { NWEar ear = project.getTasks().create(NWEAR_TASK_NAME, NWEar.class); ear.setDescription(NWEAR_TASK_DESC); ear.setGroup(PLUGIN_GROUP); project.getExtensions() .getByType(DefaultArtifactPublicationSet.class) .addCandidate(new ArchivePublishArtifact(ear)); return ear; }