Programmatically setting a layer's bounding box in Geoserver

This is already an old question, but I haven't found many example documenting this on he Web. On GeoServer version 2.5.1 the following should work (it should also work with older versions). :

Example XML

<layerGroup>

<workspace>workspace</workspace>
<name>014531_layer_group</name>
<layers>
<layer>014531_layer</layer>
<layer>014531_layer_watermark</layer>
</layers>
<styles>
<style>raster</style>
<style>sld_watermark</style>
</styles>
<bounds>
<minx>12.91</minx>
<miny>-6.97</miny>
<maxx>14.32</maxx>
<maxy>-5.44</maxy>
<crs>EPSG:4326</crs>
</bounds>
</layerGroup>

Example REST statement

sudo curl -v -u user:pwd -XPOST -d @yourxmlfile.xml -H "Content-type: text/xml" http://localhost:8080/geoserver/rest/layergroups

It doesn't take the bounding box of the underlying layer, but you could retrieve it by using a Selenium script