You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by Jochen Wiedmann <jo...@gmail.com> on 2017/12/12 12:54:07 UTC

Build Script Templates

Hi,

over the last months, I was working in a larger project in a Java
environment, but not directly a Java project. Suffice it to say, that
we have a number of Java subprojects, but generally aren't so much
interested in Java builds, etc.

There's no rule without exceptions, so I've been tasked with
streamlining these subprojects into a form, which allows to maintain
them in a simple, and uniform manner.

Not surprising, I was thinking "Maven" initially, and started to
rewrite some of these subprojects for Maven. However, it quickly
turned out, that access to the Internet is a problem in my particular
corporate environment, so I dropped Maven from the picture.

What I came up with, instead, was a set of conventions, which closely
resemble the Maven projects, and a "Maven Jar Template" (MJT). The MJT
is an Ant build script, which is generic, and shared by all our
subprojects. The actual build scripts typically specify a small set of
properties (project.name, project.version,
project.java.source.version, and the like), and import the MJT. As the
project follows the MJT conventions, that's it in most cases, apart
from things like a uber jar, etc., which aren't handled by the MJT.
However, these are mostly resolved by "overwriting" one of the
imported tasks.

In general, our build scripts are unusually small, and concise (for
Ant scripts, that is). The experiemce is so good, that I wonder, if we
couldn't start distributing some of these templates with Ant Core, or
as a separate ant-templates.jar? If so, a build script could look like
below,

Jochen

   <project name="MySampleProject" default="dist">
        <property name="project.name" value="MySampleProject"/>
        <property name="project.version" value="0.1"/>

        <!-- Specify targets, like "clean", "compile", "package", etc.
              following the Maven goals. -->
        <import resource="org/apache/ant/templates/MavenJarTemplate-0.1.xml"/>

        <!-- Specify our own targets -->
        <target name="dist" depends="clean,install"/>
   </project>


-- 
The next time you hear: "Don't reinvent the wheel!"

http://www.keystonedevelopment.co.uk/wp-content/uploads/2014/10/evolution-of-the-wheel-300x85.jpg

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org


Re: Build Script Templates

Posted by Martin Gainty <mg...@hotmail.com>.
MG>quick comments below

________________________________
From: Jochen Wiedmann <jo...@gmail.com>
Sent: Tuesday, December 12, 2017 7:54 AM
To: dev@ant.apache.org
Subject: Build Script Templates

Hi,

over the last months, I was working in a larger project in a Java
environment, but not directly a Java project. Suffice it to say, that
we have a number of Java subprojects, but generally aren't so much
interested in Java builds, etc.

There's no rule without exceptions, so I've been tasked with
streamlining these subprojects into a form, which allows to maintain
them in a simple, and uniform manner.

Not surprising, I was thinking "Maven" initially, and started to
rewrite some of these subprojects for Maven. However, it quickly
turned out, that access to the Internet is a problem in my particular
corporate environment,
MG>my internet access was problematic so i dropped IVY ..
MG>in maven you can test your pom.xml against local repository with -o option e.g.
MG>mvn -o

so I dropped Maven from the picture.

What I came up with, instead, was a set of conventions, which closely
resemble the Maven projects, and a "Maven Jar Template" (MJT). The MJT
is an Ant build script, which is generic, and shared by all our
subprojects. The actual build scripts typically specify a small set of
properties (project.name, project.version,
project.java.source.version, and the like),
MG>Nota Bene:if you add project.groupId and project.artifactId you will satisfy the GAV reference to a maven artifact

and import the MJT. As the project follows the MJT conventions, that's it in most cases, apart
from things like a uber jar, etc., which aren't handled by the MJT.
However, these are mostly resolved by "overwriting" one of the
imported tasks.
MG>same concept applies in maven where you declare template in <dependencyManagement>
MG>and / or <pluginManagement> in parent pom
MG>then later on you can 'override' either declaration for plugin or dependency in your artifact's local pom.xml

In general, our build scripts are unusually small, and concise (for
Ant scripts, that is). The experience is so good, that I wonder, if we
couldn't start distributing some of these templates with Ant Core, or
as a separate ant-templates.jar? If so, a build script could look like
below,

Jochen

   <project name="MySampleProject" default="dist">
        <property name="project.name" value="MySampleProject"/>
        <property name="project.version" value="0.1"/>

        <!-- Specify targets, like "clean", "compile", "package", etc.
              following the Maven goals. -->
        <import resource="org/apache/ant/templates/MavenJarTemplate-0.1.xml"/>
MG>do you have a mock of MavenJarTemplate-0.1.xml you can display for us?

        <!-- Specify our own targets -->
        <target name="dist" depends="clean,install"/>
MG>assume install target is declared in MavenJarTemplate-0.1.xml ?
   </project>


--
The next time you hear: "Don't reinvent the wheel!"

http://www.keystonedevelopment.co.uk/wp-content/uploads/2014/10/evolution-of-the-wheel-300x85.jpg

[http://www.keystonedevelopment.co.uk/wp-content/uploads/2014/10/evolution-of-the-wheel-300x85.jpg]


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org


Re: Build Script Templates

Posted by Stefan Bodewig <bo...@apache.org>.
On 2017-12-12, Jochen Wiedmann wrote:

> What I came up with, instead, was a set of conventions, which closely
> resemble the Maven projects, and a "Maven Jar Template" (MJT). The MJT
> is an Ant build script, which is generic, and shared by all our
> subprojects. The actual build scripts typically specify a small set of
> properties (project.name, project.version,
> project.java.source.version, and the like), and import the MJT. As the
> project follows the MJT conventions, that's it in most cases, apart
> from things like a uber jar, etc., which aren't handled by the MJT.
> However, these are mostly resolved by "overwriting" one of the
> imported tasks.

Sounds a lot like the thing we've done for the antlibs where we've got a
template build system in https://github.com/apache/ant-antlibs-common
and the individual antlibs come down to

<project default="compile" name="antunit">

  <!-- easy way to override properties -->
  <property file="build.properties"/>

  <!-- don't fork junit; regexp classes not available -->
  <property name="junit.fork" value="false" />

  <property name="javac.test-source" value="1.5"/>
  <property name="javac.test-target" value="1.5"/>

  <import file="common/build.xml"/>
</project>

(that's AntUnit, the one for compress is even shorter).

> The experiemce is so good, that I wonder, if we couldn't start
> distributing some of these templates with Ant Core, or as a separate
> ant-templates.jar? If so, a build script could look like below,

I'd see this as a collection separate from Ant's core. In a way EasyAnt
(and Krysalis years before that) tried to do something like this but may
have been too ambitious.

Having some sort of best practice template(s) without any additional
tooling required might be enough.

Stefan

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org