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 Collection<MavenDeployer> getMavenDeployers(Collection<ArtifactRepository> repositories) { Collection<MavenDeployer> result = Lists.newArrayList(); for (ArtifactRepository repository : repositories) { if (repository instanceof MavenDeployer) { result.add((MavenDeployer) repository); } } return result; }
private Set<String> getArtifactIds(Collection<MavenDeployer> deployers) { Set<String> result = Sets.newHashSet(); for (MavenDeployer deployer : deployers) { result.add(deployer.getPom().getArtifactId()); } return result; }
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"); } } }); } }); } }); }