public String extract() { Collection<Upload> tasks = project.getTasks().withType(Upload.class); Collection<ArtifactRepository> repositories = getRepositories(tasks); if (!onlyContainsMavenResolvers(repositories)) { return project.getName(); } Collection<MavenDeployer> deployers = getMavenDeployers(repositories); Set<String> artifactIds = getArtifactIds(deployers); if (artifactIds.size() == 1) { String artifactId = artifactIds.iterator().next(); if (artifactId != null && !artifactId.equals(MavenProject.EMPTY_PROJECT_ARTIFACT_ID)) { return artifactId; } } String baseName = getArchivesBaseName(); return baseName != null ? baseName : project.getName(); }
private void configureUploadArchivesTask() { configurationActionContainer.add(new Action<Project>() { public void execute(Project project) { Upload uploadArchives = project.getTasks().withType(Upload.class).findByName(BasePlugin.UPLOAD_ARCHIVES_TASK_NAME); if (uploadArchives == null) { return; } ConfigurationInternal configuration = (ConfigurationInternal) uploadArchives.getConfiguration(); Module module = configuration.getModule(); for (MavenResolver resolver : uploadArchives.getRepositories().withType(MavenResolver.class)) { MavenPom pom = resolver.getPom(); ModuleVersionIdentifier publicationId = new DefaultModuleVersionIdentifier( pom.getGroupId().equals(MavenProject.EMPTY_PROJECT_GROUP_ID) ? module.getGroup() : pom.getGroupId(), pom.getArtifactId().equals(MavenProject.EMPTY_PROJECT_ARTIFACT_ID) ? module.getName() : pom.getArtifactId(), pom.getVersion().equals(MavenProject.EMPTY_PROJECT_VERSION) ? module.getVersion() : pom.getVersion() ); publicationRegistry.registerPublication(project.getPath(), new DefaultProjectPublication(publicationId)); } } }); }
private void configureUploadArchivesTask() { configurationActionContainer.add(new Action<Project>() { public void execute(Project project) { Upload uploadArchives = project.getTasks().withType(Upload.class).findByName(UPLOAD_ARCHIVES_TASK_NAME); if (uploadArchives == null) { return; } boolean hasIvyRepo = !uploadArchives.getRepositories().withType(IvyArtifactRepository.class).isEmpty(); if (!hasIvyRepo) { return; } // Maven repos are handled by MavenPlugin ConfigurationInternal configuration = (ConfigurationInternal) uploadArchives.getConfiguration(); Module module = configuration.getModule(); ModuleVersionIdentifier publicationId = new DefaultModuleVersionIdentifier(module.getGroup(), module.getName(), module.getVersion()); publicationRegistry.registerPublication(module.getProjectPath(), new DefaultProjectPublication(publicationId)); } }); }
private void configureUploadArchivesTask() { configurationActionContainer.add(new Action<Project>() { public void execute(Project project) { Upload uploadArchives = project.getTasks().withType(Upload.class).findByName(BasePlugin.UPLOAD_ARCHIVES_TASK_NAME); if (uploadArchives == null) { return; } ConfigurationInternal configuration = (ConfigurationInternal) uploadArchives.getConfiguration(); ModuleInternal module = configuration.getModule(); for (MavenResolver resolver : uploadArchives.getRepositories().withType(MavenResolver.class)) { MavenPom pom = resolver.getPom(); ModuleVersionIdentifier publicationId = new DefaultModuleVersionIdentifier( pom.getGroupId().equals(MavenProject.EMPTY_PROJECT_GROUP_ID) ? module.getGroup() : pom.getGroupId(), pom.getArtifactId().equals(MavenProject.EMPTY_PROJECT_ARTIFACT_ID) ? module.getName() : pom.getArtifactId(), pom.getVersion().equals(MavenProject.EMPTY_PROJECT_VERSION) ? module.getVersion() : pom.getVersion() ); publicationRegistry.registerPublication(project.getPath(), new DefaultProjectPublication(publicationId)); } } }); }
private void configureUploadArchivesTask() { configurationActionContainer.add(new Action<Project>() { public void execute(Project project) { Upload uploadArchives = project.getTasks().withType(Upload.class).findByName(UPLOAD_ARCHIVES_TASK_NAME); if (uploadArchives == null) { return; } boolean hasIvyRepo = !uploadArchives.getRepositories().withType(IvyArtifactRepository.class).isEmpty(); if (!hasIvyRepo) { return; } // Maven repos are handled by MavenPlugin ConfigurationInternal configuration = (ConfigurationInternal) uploadArchives.getConfiguration(); ModuleInternal module = configuration.getModule(); ModuleVersionIdentifier publicationId = new DefaultModuleVersionIdentifier(module.getGroup(), module.getName(), module.getVersion()); publicationRegistry.registerPublication(module.getProjectPath(), new DefaultProjectPublication(publicationId)); } }); }
private Collection<ArtifactRepository> getRepositories(Collection<Upload> tasks) { Collection<ArtifactRepository> result = Lists.newArrayList(); for (Upload task : tasks) { result.addAll(task.getRepositories()); } return result; }
private void configureUploadTasks(final DefaultDeployerFactory deployerFactory) { project.getTasks().withType(Upload.class, new Action<Upload>() { public void execute(Upload upload) { RepositoryHandler repositories = upload.getRepositories(); DefaultRepositoryHandler handler = (DefaultRepositoryHandler) repositories; DefaultMavenRepositoryHandlerConvention repositoryConvention = new DefaultMavenRepositoryHandlerConvention(handler, deployerFactory); new DslObject(repositories).getConvention().getPlugins().put("maven", repositoryConvention); } }); }
private void configureInstall(Project project) { Upload installUpload = project.getTasks().create(INSTALL_TASK_NAME, Upload.class); Configuration configuration = project.getConfigurations().getByName(Dependency.ARCHIVES_CONFIGURATION); installUpload.setConfiguration(configuration); MavenRepositoryHandlerConvention repositories = new DslObject(installUpload.getRepositories()).getConvention().getPlugin(MavenRepositoryHandlerConvention.class); repositories.mavenInstaller(); installUpload.setDescription("Installs the 'archives' artifacts into the local Maven repository."); }
private Upload createUploadTask(String name, final Configuration configuration, final Project project) { Upload upload = project.getTasks().create(name, Upload.class); upload.setDescription("Uploads all artifacts belonging to " + configuration); upload.setGroup(BasePlugin.UPLOAD_GROUP); upload.setConfiguration(configuration); upload.setUploadDescriptor(true); upload.getConventionMapping().map("descriptorDestination", new Callable<File>() { public File call() throws Exception { return new File(project.getBuildDir(), "ivy.xml"); } }); return upload; }
public static void setupDefaultConfig( @NonNull final Project project, @NonNull Configuration configuration) { // The library artifact is published (inter-project( for the "default" configuration so // we make sure "default" extends from the actual configuration used for building. Configuration defaultConfig = project.getConfigurations().getAt("default"); defaultConfig.setExtendsFrom(Collections.singleton(configuration)); // for the maven publication (for now), we need to manually include all the configuration // object in a special mapping. // It's not possible to put the top level config object as extended from config won't // be included. final Set<Configuration> flattenedConfigs = flattenConfigurations(configuration); project.getPlugins().withType(MavenPlugin.class, new Action<MavenPlugin>() { @Override public void execute(MavenPlugin mavenPlugin) { project.getTasks().withType(Upload.class, new Action<Upload>() { @Override public void execute(Upload upload) { upload.getRepositories().withType( MavenDeployer.class, new Action<MavenDeployer>() { @Override public void execute(MavenDeployer mavenDeployer) { for (Configuration config : flattenedConfigs) { mavenDeployer.getPom().getScopeMappings().addMapping( 300, project.getConfigurations().getByName( config.getName()), "compile"); } } }); } }); } }); }
private Upload createUploadTask(String name, final Configuration configuration, final Project project) { Upload upload = project.getTasks().create(name, Upload.class); upload.setDescription(String.format("Uploads all artifacts belonging to %s", configuration)); upload.setGroup(BasePlugin.UPLOAD_GROUP); upload.setConfiguration(configuration); upload.setUploadDescriptor(true); upload.getConventionMapping().map("descriptorDestination", new Callable<File>() { public File call() throws Exception { return new File(project.getBuildDir(), "ivy.xml"); } }); return upload; }