private Optional<File> attemptLocalResolutionFromPublication(DependencyAdaptor da, Stream<Publication> publications) { //If any of these is null, we'll fall back to external repositories as well. final String group = da.getGroup(); if ( group == null ) return null; final String version = da.getVersion(); if ( version == null ) return null; final String module = da.getModule(); if ( module == null ) return null; final Optional<File> anyMatch = publications .filter( d -> d instanceof MavenPublication ) .map( d -> (MavenPublication) d ) .filter( m -> module.equals( m.getArtifactId() ) && group.equals( m.getGroupId() ) && version.equals( m.getVersion() ) ) .map( MavenPublication::getArtifacts ) .flatMap( MavenArtifactSet::stream ) .filter( m -> m.getFile() != null ) .map( m -> m.getFile() ) .filter( f -> ((!f.getName().endsWith( "-sources.jar" ))&&(!f.getName().endsWith( "-javadoc.jar" ))) ) .findAny(); return anyMatch; }
public void execute(PublicationContainer publications) { MavenPublication p = publications.create(PUBLICATION_NAME, MavenPublication.class, new Action<MavenPublication>() { public void execute(MavenPublication publication) { publication.from(project.getComponents().getByName("java")); publication.artifact(sourcesJar); publication.artifact(javadocJar); publication.setArtifactId(((Jar) project.getTasks().getByName("jar")).getBaseName()); PomCustomizer.customizePom(project, conf, publication); } }); LOG.info("{} - configured '{}' publication", project.getPath(), p.getArtifactId()); } });
MavenPom pom = pub.getPom(); pom.developers( devs -> { devs.developer( dev -> { dev.getName().set( "Caleb Cushing" ); dev.getEmail().set( "xenoterracide@gmail.com" ); dev.getUrl().set( "https://xenoterracide.com" ); } ); } ); pub.from( project.getComponents().getAt( "java" ) ); pub.artifact( provider.get() ); } ); } );
p.setArtifactId(publicationConfig.getArtifactId()); Validate.notNull(compileConfigurations), Validate.notNull(artifacts)); p.pom(pom -> pom.withXml(xml -> configurator.configurePom(Validate.notNull(xml)))); p.artifact(a);
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); } }
@Override public void apply(Project project) { // Ensure publishing exists before configuring IR publishing project.getPluginManager().apply(MavenPublishPlugin.class); project.getPluginManager().apply(ConjurePlugin.class); CompileIrTask compileIr = (CompileIrTask) project.getTasks().findByName(ConjurePlugin.CONJURE_IR); if (compileIr == null) { throw new GradleException("Unable to find compileIr task"); } // Configure publishing project.getExtensions().configure(PublishingExtension.class, publishing -> { publishing.publications(publications -> { publications.create( "conjure", MavenPublication.class, mavenPublication -> mavenPublication.artifact( compileIr.getOutputFile(), mavenArtifact -> { mavenArtifact.builtBy(compileIr); mavenArtifact.setExtension("conjure.json"); })); }); }); } }
@Override public void execute(Project project) { JavaPluginConvention java = project.getConvention().getPlugin(JavaPluginConvention.class); PublishingExtension publishing = project.getExtensions().getByType(PublishingExtension.class); Task sourceJar = project.getTasks().create("sourceJar", Jar.class, jar -> { jar.from(java.getSourceSets().getByName("main").getAllSource()); }); publishing.publications(publications -> { publications.create("mavenJava", MavenPublication.class, publication -> { publication.artifact(sourceJar, artifact -> { artifact.setClassifier("sources"); }); }); }); } }
public void execute(XmlProvider xml) { String archivesBaseName = (String) project.getProperties().get("archivesBaseName"); File contributorsFile = contributorsFile(project); LOG.info(" Read project contributors from file: " + contributorsFile.getAbsolutePath()); // It can happens that contributorsFile doesn't exist e.g. when shipkit.team.contributors is NOT empty ProjectContributorsSet contributorsFromGitHub = new ProjectContributorsSerializer() .deserialize(IOUtil.readFullyOrDefault(contributorsFile, "[]")); LOG.info(" Customizing pom for publication " + publication.getName() + " in " + project.toString() + "\n - Module name (project.archivesBaseName): " + archivesBaseName + "\n - Description (project.description): " + project.getDescription() + "\n - GitHub repository (project.rootProject.shipkit.gitHub.repository): " + conf.getGitHub().getRepository() + "\n - Developers (project.rootProject.shipkit.team.developers): " + StringUtil.join(conf.getTeam().getDevelopers(), ", ") + "\n - Contributors (project.rootProject.shipkit.team.contributors): " + StringUtil.join(conf.getTeam().getContributors(), ", ") + "\n - Contributors read from GitHub: " + StringUtil.join(contributorsFromGitHub.toConfigNotation(), ", ")); customizePom(xml.asNode(), conf, archivesBaseName, project.getDescription(), contributorsFromGitHub); } });
MavenPom pom = pub.getPom(); pom.developers( devs -> { devs.developer( dev -> { dev.getName().set( "Caleb Cushing" ); dev.getEmail().set( "xenoterracide@gmail.com" ); dev.getUrl().set( "https://xenoterracide.com" ); } ); } ); pub.from( project.getComponents().getAt( "java" ) ); pub.artifact( provider.get() ); } ); } );
p.setArtifactId(publicationConfig.getArtifactId()); Validate.notNull(compileConfigurations), Validate.notNull(artifacts)); p.pom(pom -> pom.withXml(xml -> configurator.configurePom(Validate.notNull(xml)))); p.artifact(a);
/** * Customizes the pom. The method requires following properties on root project to function correctly: */ public static void customizePom(final Project project, final ShipkitConfiguration conf, final MavenPublication publication) { publication.getPom().withXml(new Action<XmlProvider>() { public void execute(XmlProvider xml) { String archivesBaseName = (String) project.getProperties().get("archivesBaseName"); File contributorsFile = contributorsFile(project); LOG.info(" Read project contributors from file: " + contributorsFile.getAbsolutePath()); // It can happens that contributorsFile doesn't exist e.g. when shipkit.team.contributors is NOT empty ProjectContributorsSet contributorsFromGitHub = new ProjectContributorsSerializer() .deserialize(IOUtil.readFullyOrDefault(contributorsFile, "[]")); LOG.info(" Customizing pom for publication " + publication.getName() + " in " + project.toString() + "\n - Module name (project.archivesBaseName): " + archivesBaseName + "\n - Description (project.description): " + project.getDescription() + "\n - GitHub repository (project.rootProject.shipkit.gitHub.repository): " + conf.getGitHub().getRepository() + "\n - Developers (project.rootProject.shipkit.team.developers): " + StringUtil.join(conf.getTeam().getDevelopers(), ", ") + "\n - Contributors (project.rootProject.shipkit.team.contributors): " + StringUtil.join(conf.getTeam().getContributors(), ", ") + "\n - Contributors read from GitHub: " + StringUtil.join(contributorsFromGitHub.toConfigNotation(), ", ")); customizePom(xml.asNode(), conf, archivesBaseName, project.getDescription(), contributorsFromGitHub); } }); }
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); } }
public void execute(XmlProvider xml) { String archivesBaseName = (String) project.getProperties().get("archivesBaseName"); File contributorsFile = contributorsFile(project); LOG.info(" Read project contributors from file: " + contributorsFile.getAbsolutePath()); // It can happens that contributorsFile doesn't exist e.g. when shipkit.team.contributors is NOT empty ProjectContributorsSet contributorsFromGitHub = new AllContributorsSerializer() .deserialize(IOUtil.readFullyOrDefault(contributorsFile, "[]")); LOG.info(" Customizing pom for publication " + publication.getName() + " in " + project.toString() + "\n - Module name (project.archivesBaseName): " + archivesBaseName + "\n - Description (project.description): " + project.getDescription() + "\n - GitHub repository (project.rootProject.shipkit.gitHub.repository): " + conf.getGitHub().getRepository() + "\n - Developers (project.rootProject.shipkit.team.developers): " + StringUtil.join(conf.getTeam().getDevelopers(), ", ") + "\n - Contributors (project.rootProject.shipkit.team.contributors): " + StringUtil.join(conf.getTeam().getContributors(), ", ") + "\n - Contributors read from GitHub: " + StringUtil.join(contributorsFromGitHub.toConfigNotation(), ", ")); customizePom(xml.asNode(), conf, archivesBaseName, project.getDescription(), contributorsFromGitHub); } });
} ); pubs.create( "mavenJava", MavenPublication.class, pub -> { MavenPom pom = pub.getPom(); pom.developers( devs -> { devs.developer( dev -> { dev.getName().set( "Caleb Cushing" ); dev.getEmail().set( "xenoterracide@gmail.com" ); dev.getUrl().set( "https://xenoterracide.com" ); } ); } ); pub.from( project.getComponents().getAt( "java" ) ); pub.artifact( provider.get() ); } ); } );
/** * Customizes the pom. The method requires following properties on root project to function correctly: */ public static void customizePom(final Project project, final ReleaseConfiguration conf, final MavenPublication publication) { publication.getPom().withXml(new Action<XmlProvider>() { public void execute(XmlProvider xml) { String archivesBaseName = (String) project.getProperties().get("archivesBaseName"); File contributorsFile = contributorsFile(project); LOG.info(" Read project contributors from file: " + contributorsFile.getAbsolutePath()); // It can happens that contributorsFile doesn't exist e.g. when shipkit.team.contributors is NOT empty ProjectContributorsSet contributorsFromGitHub = new AllContributorsSerializer() .deserialize(IOUtil.readFullyOrDefault(contributorsFile, "[]")); LOG.info(" Customizing pom for publication " + publication.getName() + " in " + project.toString() + "\n - Module name (project.archivesBaseName): " + archivesBaseName + "\n - Description (project.description): " + project.getDescription() + "\n - GitHub repository (project.rootProject.shipkit.gitHub.repository): " + conf.getGitHub().getRepository() + "\n - Developers (project.rootProject.shipkit.team.developers): " + StringUtil.join(conf.getTeam().getDevelopers(), ", ") + "\n - Contributors (project.rootProject.shipkit.team.contributors): " + StringUtil.join(conf.getTeam().getContributors(), ", ") + "\n - Contributors read from GitHub: " + StringUtil.join(contributorsFromGitHub.toConfigNotation(), ", ")); customizePom(xml.asNode(), conf, archivesBaseName, project.getDescription(), contributorsFromGitHub); } }); }
public void execute(XmlProvider xml) { String archivesBaseName = (String) project.getProperties().get("archivesBaseName"); File contributorsFile = contributorsFile(project); LOG.info(" Read project contributors from file: " + contributorsFile.getAbsolutePath()); // It can happens that contributorsFile doesn't exist e.g. when shipkit.team.contributors is NOT empty ProjectContributorsSet contributorsFromGitHub = new ProjectContributorsSerializer() .deserialize(IOUtil.readFullyOrDefault(contributorsFile, "[]")); LOG.info(" Customizing pom for publication " + publication.getName() + " in " + project.toString() + "\n - Module name (project.archivesBaseName): " + archivesBaseName + "\n - Description (project.description): " + project.getDescription() + "\n - GitHub repository (project.rootProject.shipkit.gitHub.repository): " + conf.getGitHub().getRepository() + "\n - Developers (project.rootProject.shipkit.team.developers): " + StringUtil.join(conf.getTeam().getDevelopers(), ", ") + "\n - Contributors (project.rootProject.shipkit.team.contributors): " + StringUtil.join(conf.getTeam().getContributors(), ", ") + "\n - Contributors read from GitHub: " + StringUtil.join(contributorsFromGitHub.toConfigNotation(), ", ")); customizePom(xml.asNode(), conf, archivesBaseName, project.getDescription(), contributorsFromGitHub); } });
/** * Customizes the pom. The method requires following properties on root project to function correctly: */ public static void customizePom(final Project project, final ShipkitConfiguration conf, final MavenPublication publication) { publication.getPom().withXml(new Action<XmlProvider>() { public void execute(XmlProvider xml) { String archivesBaseName = (String) project.getProperties().get("archivesBaseName"); File contributorsFile = contributorsFile(project); LOG.info(" Read project contributors from file: " + contributorsFile.getAbsolutePath()); // It can happens that contributorsFile doesn't exist e.g. when shipkit.team.contributors is NOT empty ProjectContributorsSet contributorsFromGitHub = new ProjectContributorsSerializer() .deserialize(IOUtil.readFullyOrDefault(contributorsFile, "[]")); LOG.info(" Customizing pom for publication " + publication.getName() + " in " + project.toString() + "\n - Module name (project.archivesBaseName): " + archivesBaseName + "\n - Description (project.description): " + project.getDescription() + "\n - GitHub repository (project.rootProject.shipkit.gitHub.repository): " + conf.getGitHub().getRepository() + "\n - Developers (project.rootProject.shipkit.team.developers): " + StringUtil.join(conf.getTeam().getDevelopers(), ", ") + "\n - Contributors (project.rootProject.shipkit.team.contributors): " + StringUtil.join(conf.getTeam().getContributors(), ", ") + "\n - Contributors read from GitHub: " + StringUtil.join(contributorsFromGitHub.toConfigNotation(), ", ")); customizePom(xml.asNode(), conf, archivesBaseName, project.getDescription(), contributorsFromGitHub); } }); }