Buildr won't generate a POM in projects with multiple packages

115 views Asked by At

I have a Java project that uses Apache Buildr as its build tool. It installs a WAR and two ZIP archives to a Maven repository. However, with Buildr 1.5.6, it seems that when the instructions to build the ZIP archives are added to the buildfile there is no .pom file generated in the output folder.

To be specific, when executing buildr clean package using this buildfile code:

task :package => [:get_svn_version] 
SQL_ARCHIVE = "Project-#{VERSION_NUMBER}-sql.zip"
package(:zip, :file => _(:target, SQL_ARCHIVE)).include("src/main/sql")
CONF_ARCHIVE = "Project-#{VERSION_NUMBER}-conf.zip"
package(:zip, :file => _(:target, CONF_ARCHIVE)).include(_("conf"))
package(:war).with :libs => [PACKAGE_ONLY_DEPS, COMPILE_PACKAGE_DEPS]

...Buildr produces an output folder containing:

atg@host:> ls target classes Project-1.1-SNAPSHOT-conf.zip Project-1.1-SNAPSHOT.war test js-test Project-1.1-SNAPSHOT-sql.zip resources

Whereas, just this:

task :package => [:get_svn_version]
package(:war).with :libs => [PACKAGE_ONLY_DEPS, COMPILE_PACKAGE_DEPS]

...outputs:

atg@host:> ls target classes js-test Project-1.1-SNAPSHOT.pom Project-1.1-SNAPSHOT.war resources test

As you can see, the .pom file is not generated in the former case, so buildr install cannot subsequently succeed. My question, therefore, is how can I get Buildr to create a .pom file as well as my WAR and ZIP archives?

EDIT:

The following simple buildfile is enough to reproduce the issue:

# Generated by Buildr 1.5.6, change to your liking
repositories.remote << 'http://repo1.maven.org/maven2'

DUMMY_DEPENDENCIES = 'org.hamcrest:hamcrest-core:jar:1.3'

desc "Test project for stackoverflow.com"
define 'no-pom' do
  project.group = "test"
  project.version = '1.0-SNAPSHOT'

  test.with DUMMY_DEPENDENCIES

  package(:zip, :file => _("target", "configuration.zip")).include(_("conf"))
  package(:war).with :libs => [DUMMY_DEPENDENCIES]

end

This is based on the classic Maven2 auto-generated project, with App.java and the "rigorous" AppTest.java. All I added to it was the conf folder in the project root, which just contains one dummy text file.

If you run the above then you get a WAR and "configuration.zip" created but no .pom file. If you comment out the instruction to zip the conf folder then you get a .pom file generated along with the WAR file.

1

There are 1 answers

0
ATG On

In the absence of any response to this question or acknowledgement of this as a Buildr bug, I've managed to work around the problem by modifying the offending file in Buildr.

In the file /usr/lib64/ruby/gems/2.5.0/gems/buildr-1.5.6/lib/buildr/java/custom_pom.rb (path may vary depending on Ruby/Buildr version) look for this line:

candidates = project.packages.select{|p| p.classifier.nil? }.collect{|p|p.type.to_s}

It's line 181 for me, so it'll probably be there or thereabouts for most people. Change it to read as follows:

candidates = project.packages.select{|p|defined? p.classifier &&p.classifier.nil? }.collect{|p|p.type.to_s}

Upon saving the file, you should be able to run buildr clean package and buildr install without any difficulty.

Disclaimer: I am neither a Ruby programmer nor a Buildr developer, so this may be a breaking change for other areas of the software. All I can say is that it works for me and has fixed this issue on my machine.