Publish .war instead of .jar file

500 views
Skip to first unread message

dave

unread,
Aug 9, 2011, 2:46:39 PM8/9/11
to simple-build-tool
I have a Lift web application that I'm building with sbt-0.10.1. When
I publish the project, I would rather publish the .war file than
the .jar file. How can I modify my build.sbt file to accomplish this?

Thanks!
dave
<><

dave

unread,
Aug 9, 2011, 3:38:30 PM8/9/11
to simple-build-tool
After playing around a bit, I've found something that works. Now, is
this the best way, or is there a better way. I still haven't
completely wrapped my head around the syntax for a .sbt file.

// disable .jar publishing
publishArtifact in (Compile, packageBin) := false

// create an Artifact for publishing the .war file
artifact in (Compile, packageWar) ~= { (art: Artifact) =>
art.copy(`type` = "war", extension = "war")
}

// add the .war file to what gets published
addArtifact(artifact in (Compile, packageWar), packageWar)

Thanks!
dave
<><

Mark Harrah

unread,
Aug 9, 2011, 9:38:38 PM8/9/11
to simple-b...@googlegroups.com

This is the right way and I think it would make a good addition to the wiki if you are interested in adding it. Perhaps it would be a nice enhancement if the web plugin supported something like:

publishArtifact in packageWar := true

-Mark

> Thanks!
> dave
> <><
>

dave

unread,
Aug 10, 2011, 10:13:45 AM8/10/11
to simple-build-tool
On Aug 9, 8:38 pm, Mark Harrah <dmhar...@gmail.com> wrote:
> This is the right way and I think it would make a good addition to the wiki if you are interested in adding it.  Perhaps it would be a nice enhancement if the web plugin supported something like:
>
>  publishArtifact in packageWar := true
>
> -Mark

Thanks. I've updated the wiki. But I'm having a problem publishing
snapshots to a Maven-style Artifactory repository. I'm not sure if
it's a bug with SBT or Artifactory, though.

I have the Artifactory repo configured to use time-based version
numbers for the name of SNAPSHOTs (Maven Snapshot Version Behavior ==
Unique).

In my build.sbt file, I have publishMavenStyle := true.

When the artifacts are deployed, the .pom, -javadoc.jar and -
sources.jar are all deployed properly (with a name something like
artifactId-0.0.1-20110810.135923-2.pom ). But the .war is deployed
with a different version number (in this case, it was
artifactId-0.0.1-20110810.135923-3.war).

Any thoughts on what the problem could be?

dave
<><

Mark Harrah

unread,
Aug 11, 2011, 6:53:50 AM8/11/11
to simple-b...@googlegroups.com

This is very likely not under sbt's control. I believe Artifactory will take an artifact published as 0.0.1-SNAPSHOT and produce artifacts with the standard Maven snapshot behavior like you see. The final -N is determined from existing artifacts. In this case, I would guess that you had a -1.war but not a -1.pom. If you clean your snapshots (starting from scratch), I think you will get consistent numbers.

-Mark

> dave
> <><
>

dave

unread,
Aug 11, 2011, 9:42:02 PM8/11/11
to simple-build-tool
Cleaning snapshots didn't help :-(

Changing the repository's snapshot behavior to Deployer gets the SBT
artifacts to publish as -SNAPSHOT instead of timestamps. While not
exactly what I want, it should work for now.

If I have time to put together a simple test case, I may post it to
the Artifactory forums.

Thanks!
dave
<><

>
> -Mark

Mark Harrah

unread,
Aug 14, 2011, 7:26:48 PM8/14/11
to simple-b...@googlegroups.com
On Thu, 11 Aug 2011 18:42:02 -0700 (PDT)
dave <leed...@yahoo.com> wrote:

> On Aug 11, 5:53 am, Mark Harrah <dmhar...@gmail.com> wrote:
> > On Wed, 10 Aug 2011 07:13:45 -0700 (PDT)
> > dave <leedm...@yahoo.com> wrote:
> > > Thanks.  I've updated the wiki.  But I'm having a problem publishing
> > > snapshots to a Maven-style Artifactory repository.  I'm not sure if
> > > it's a bug with SBT or Artifactory, though.
> >
> > > I have the Artifactory repo configured to use time-based version
> > > numbers for the name of SNAPSHOTs (Maven Snapshot Version Behavior ==
> > > Unique).
> >
> > > In my build.sbt file, I have publishMavenStyle := true.
> >
> > > When the artifacts are deployed, the .pom, -javadoc.jar and -
> > > sources.jar are all deployed properly (with a name something like
> > > artifactId-0.0.1-20110810.135923-2.pom ).  But the .war is deployed
> > > with a different version number (in this case, it was
> > > artifactId-0.0.1-20110810.135923-3.war).
> >
> > > Any thoughts on what the problem could be?
> >
> > This is very likely not under sbt's control.  I believe Artifactory will take an artifact published as 0.0.1-SNAPSHOT and produce artifacts with the standard Maven snapshot behavior like you see.  The final -N is determined from existing artifacts.  In this case, I would guess that you had a -1.war but not a -1.pom.  If you clean your snapshots (starting from scratch), I think you will get consistent numbers.
>
> Cleaning snapshots didn't help :-(

To clarify, I meant cleaning them on the repository, not locally.

Assuming that is what you did, this means that you have a -2.pom and a -3.war, but no -2.war?

-Mark

dave

unread,
Aug 15, 2011, 10:46:27 AM8/15/11
to simple-build-tool
On Aug 14, 6:26 pm, Mark Harrah <dmhar...@gmail.com> wrote:
> To clarify, I meant cleaning them on the repository, not locally.
>
> Assuming that is what you did, this means that you have a -2.pom and a -3.war, but no -2.war?

Yes, I cleaned them on the repository.

And yes, there's a -2.pom and a -3.war, but no -2.war (and no -3.pom,
either).

dave
<><

> -Mark

John Sullivan

unread,
Oct 3, 2011, 9:42:50 AM10/3/11
to simple-build-tool
Hi there!

I'm trying to replicate this in a full configuration build and I'm
having problems. When I copy those three lines into a call to the
settings method, I get a compiler error. Here's my code:

lazy val server = Project(
...
).settings(
WebPlugin.webSettings: _*
).settings(
publishArtifact in (Compile, packageBin) := false,
artifact in (Compile, packageWar) ~= {
(art: Artifact) => art.copy(`type` = "war", extension = "war")
},
addArtifact(artifact in (Compile, packageWar), packageWar)
)

Here's the compile error:

[error] .../project/ToolkitBuild.scala:152: type mismatch;
[error] found : sbt.Project.SettingsDefinition
[error] required: sbt.Project.Setting[_]
[error] addArtifact(artifact in (Compile, packageWar), packageWar)
[error] ^
[error] one error found

Has something changed, or is this something that works in a simple
configuration build and not a full configuration build?

Thanks! -John

On Aug 9, 9:38 pm, Mark Harrah <dmhar...@gmail.com> wrote:
> On Tue, 9 Aug 2011 12:38:30 -0700 (PDT)
>
>
>
>
>
>
>
>
>
> dave <leedm...@yahoo.com> wrote:
> > On Aug 9, 1:46 pm, dave <leedm...@yahoo.com> wrote:
> > > I have a Lift web application that I'm building with sbt-0.10.1.  When
> > > I publish the project, I would rather publish the .war file than
> > > the .jar file.  How can I modify my build.sbt file to accomplish this?
>
> > After playing around a bit, I've found something that works.  Now, is
> > this the best way, or is there a better way.  I still haven't
> > completely wrapped my head around the syntax for a .sbt file.
>
> >     // disable .jar publishing
> >     publishArtifact in (Compile, packageBin) := false
>
> >     // create an Artifact for publishing the .war file
> >     artifact in (Compile,packageWar) ~= { (art: Artifact) =>
> >       art.copy(`type` = "war", extension = "war")
> >     }
>
> >     // add the .war file to what gets published
> >     addArtifact(artifact in (Compile,packageWar),packageWar)
>
> This is the right way and I think it would make a good addition to the wiki if you are interested in adding it.  Perhaps it would be a nice enhancement if the web plugin supported something like:
>
>  publishArtifact inpackageWar:= true
>
> -Mark
>
>
>
>
>
>
>
> > Thanks!
> > dave
> > <><

Mark Harrah

unread,
Oct 4, 2011, 10:52:48 AM10/4/11
to simple-b...@googlegroups.com
Hi John,

Call the settings method to convert a SettingsDefinition to a
Seq[Setting[_]]. I've updated the Artifacts page with this
information:

https://github.com/harrah/xsbt/wiki/Artifacts/

-Mark

> --
> You received this message because you are subscribed to the Google Groups
> "simple-build-tool" group.
> To post to this group, send email to simple-b...@googlegroups.com.
> To unsubscribe from this group, send email to
> simple-build-t...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/simple-build-tool?hl=en.
>
>

Reply all
Reply to author
Forward
0 new messages