Search in sources :

Example 1 with TaskContainer

use of org.gradle.api.tasks.TaskContainer in project atlas by alibaba.

the class PublishHooker method hookPublish.

public void hookPublish() {
    project.getTasks().whenTaskAdded(new Action<Task>() {

        @Override
        public void execute(Task task) {
            if ("publishMavenPublicationToMavenRepository".equals(task.getName())) {
                publishTask = (PublishToMavenRepository) task;
                task.setEnabled(false);
                if (null != hookTask) {
                    hookTask.setRepository(publishTask.getRepository());
                    hookTask.setPublication(publishTask.getPublication());
                }
            }
        }
    });
    final TaskContainer tasks = project.getTasks();
    Task publishLifecycleTask = tasks.getByName(PublishingPlugin.PUBLISH_LIFECYCLE_TASK_NAME);
    String taskName = "publishMavenPublicationToMavenRepositoryHook";
    hookTask = tasks.create(taskName, PublishToMavenRepositoryHook.class, new Action<PublishToMavenRepositoryHook>() {

        public void execute(PublishToMavenRepositoryHook publishTask) {
            publishTask.setGroup(PublishingPlugin.PUBLISH_TASK_GROUP);
        }
    });
    publishLifecycleTask.dependsOn(taskName);
}
Also used : Task(org.gradle.api.Task) Action(org.gradle.api.Action) TaskContainer(org.gradle.api.tasks.TaskContainer) PublishToMavenRepository(org.gradle.api.publish.maven.tasks.PublishToMavenRepository) PublishToMavenRepositoryHook(com.taobao.android.builder.tasks.maven.PublishToMavenRepositoryHook)

Example 2 with TaskContainer

use of org.gradle.api.tasks.TaskContainer in project gradle by gradle.

the class MavenPublishPlugin method apply.

public void apply(final Project project) {
    project.getPluginManager().apply(PublishingPlugin.class);
    final TaskContainer tasks = project.getTasks();
    final Task publishLocalLifecycleTask = tasks.create(PUBLISH_LOCAL_LIFECYCLE_TASK_NAME);
    publishLocalLifecycleTask.setDescription("Publishes all Maven publications produced by this project to the local Maven cache.");
    publishLocalLifecycleTask.setGroup(PublishingPlugin.PUBLISH_TASK_GROUP);
    // Can't move this to rules yet, because it has to happen before user deferred configurable actions
    project.getExtensions().configure(PublishingExtension.class, new Action<PublishingExtension>() {

        public void execute(PublishingExtension extension) {
            // Register factory for MavenPublication
            extension.getPublications().registerFactory(MavenPublication.class, new MavenPublicationFactory(dependencyMetaDataProvider, instantiator, fileResolver));
        }
    });
}
Also used : TaskContainer(org.gradle.api.tasks.TaskContainer) MavenPublication(org.gradle.api.publish.maven.MavenPublication) DefaultMavenPublication(org.gradle.api.publish.maven.internal.publication.DefaultMavenPublication) PublishingExtension(org.gradle.api.publish.PublishingExtension)

Example 3 with TaskContainer

use of org.gradle.api.tasks.TaskContainer in project gradle by gradle.

the class EclipsePlugin method maybeAddTask.

private static <T extends Task> void maybeAddTask(Project project, IdePlugin plugin, String taskName, Class<T> taskType, Action<T> action) {
    TaskContainer tasks = project.getTasks();
    if (tasks.findByName(taskName) != null) {
        return;
    }
    T task = tasks.create(taskName, taskType);
    action.execute(task);
    plugin.addWorker(task);
}
Also used : TaskContainer(org.gradle.api.tasks.TaskContainer)

Aggregations

TaskContainer (org.gradle.api.tasks.TaskContainer)3 PublishToMavenRepositoryHook (com.taobao.android.builder.tasks.maven.PublishToMavenRepositoryHook)1 Action (org.gradle.api.Action)1 Task (org.gradle.api.Task)1 PublishingExtension (org.gradle.api.publish.PublishingExtension)1 MavenPublication (org.gradle.api.publish.maven.MavenPublication)1 DefaultMavenPublication (org.gradle.api.publish.maven.internal.publication.DefaultMavenPublication)1 PublishToMavenRepository (org.gradle.api.publish.maven.tasks.PublishToMavenRepository)1