Extending IvyPublishPlugin doesn't result in publications


(Thorsten Schöning) #1

I’m using a customized publication using Ivy in one of my projects and tried to externalize that into a Java plugin. So I simply created a class extending IvyPublishPlugin and am applying my own class to the project. In the apply-method I’m forwarding to the base class, because I hoped that would be enough already to properly configure the plugin with all its tasks etc.

The problem is that when I’m trying to access the publications which should have been created by IvyPublishPlugin, there aren’t any. I have the feeling I’m simply too early or such, but don’t know further and didn’t find anything regarding that topic of help.

@Override
public void apply(Project project)
{
	super.apply(project);

	this.project = project;
	//this.configPublication();
	//this.configRepo();

	project.afterEvaluate(new Action<Project>()
	{
		@Override
		public void execute(Project paramT)
		{
			CustomIvyPublish.this.configPublication();
			CustomIvyPublish.this.configRepo();
		}
	});

	/*project.getExtensions().configure(	PublishingExtension.class,
										new Action<PublishingExtension>()
	{
		@Override
		public void execute(PublishingExtension extension)
		{
			CustomIvyPublish.this.configPublication();
			CustomIvyPublish.this.configRepo();
		}
	});*/
}

private void configPublication()
{
	// TODO cleanup
	Project					project		= this.project;
	PublishingExtension		publishing	= this.getPusblishing();
	Class<IvyPublication>	pubsType	= IvyPublication.class;
	//Class<IvyPublicationInternal>	pubsType	= IvyPublicationInternal.class;
	//Class<DefaultIvyPublication>	pubsType	= DefaultIvyPublication.class;

	publishing.publications(new Action<PublicationContainer>()
	{
		@Override
		public void execute(PublicationContainer pubs)
		{
			Logger logger = CustomIvyPublish.this.project.getLogger();
			System.err.println("alles murks: ".concat(Integer.toString(pubs.size())));
			pubs.forEach((pub) -> { System.err.println(pub.toString()); });

			IvyPublication		pub			= pubs.withType(pubsType).iterator().next();
			JavadocToJar		task		= JavadocToJar.findSelf(project);
			Map<String, Object>	artifact	= ImmutableMap.of(	"source",	task,
																"type",		"javadoc");

			pub.from(project.getComponents().findByName("java"));
			pub.artifact(artifact);
			CustomIvyPublish.this.configPubArtifacts(pub);
		}
	});
}

PublicationContainer is always empty.

Is it even possible to extend some plugin this way? If so, when and how am I able to access the publications? Am I even able to reconfigure them at that point?

Thanks!


(Thorsten Schöning) #2

It seems I have some progress, the publication simply needs to be created instead of queried only. My build.gradle contained such a statement as well and that needs to be transformed to Java:

publishing
{
	publications
	{
		coreWithJavadocAndDeps(IvyPublication)
		{

Needs to get:

	pubCont.create(	"coreWithJavadocAndDeps",
					IvyPublication.class,
					new Action<IvyPublication>()
	{
		@Override
		public void execute(IvyPublication pub)
		{
			JavadocToJar		task		= JavadocToJar.findSelf(project);
			Map<String, Object>	artifact	= ImmutableMap.of(	"source",	task,
																"type",		"javadoc");

			pub.from(project.getComponents().findByName("java"));
			pub.artifact(artifact);
			CustomIvyPublish.this.configPubArtifacts(pub);
		}
	});

I have a publication now, now I need to get the repo running…


(Thorsten Schöning) #3

A repo simply needs to be created as well, again pretty much like in the build.gradle before:

	repos.ivy(new Action<IvyArtifactRepository>()
	{
		@Override
		public void execute(IvyArtifactRepository repo)
		{
			Path deployDir = Main.getDeployDir(project);

			repo.setUrl(deployDir.toUri());
			repo.layout("pattern", new Action<DefaultIvyPatternRepositoryLayout>()
			{
				@Override
				public void execute(DefaultIvyPatternRepositoryLayout layout)
				{
					layout.artifact("[artifact]-[type].[ext]");
					layout.ivy(		"ivy/[module]/[artifact].[ext]");
				}
			});
		}
	});

Both of the changes work as expected, I get the same results like with build.gradle before.