Ant: best way to configure system-specific properties?

I have several files / executables that may be different depending on which computer I run them on, and I would like to abstract them somehow through the ant properties. What is the best way to do this? Is there a system ant tuning script that is being called? Or can I make such a script?

+5
source share
3 answers

In addition to Vladimir’s decision, you can have a default properties file for each OS or another on which you can deploy your build system. Use $ {os.name} (and other Java system properties) to configure the path. for example

<property file="build-${os.name}.properties">

These files can be saved and verified in your version control system.

+10

build.properties build-local.properties.

, , - . , - .

: / Akr

, , . .

Ant script (: Ant ):

<property file="build-local.properties"/>
<property file="build.properties"/>
<property file="build-${os.name}.properties">
+8

ant properties.xml, , .

template.xml, ( ant):

<?xml version="1.0" encoding="UTF-8"?>
<project
  name="workspace-properties"
>
  <dirname
    property="workspace-properties.basedir"
    file="${ant.file.workspace-properties}"
  />

  <!--
    ==========================================================
    Load Environment Variables
    ==========================================================
  -->
  <!-- #Load environment variables -->
  <property environment="env" />

  <!-- this is here to deal with the fact that an IntelliJ IDEA build
    has no ant home
  -->
  <property
    name="ant.home"
    value="${env.ANT_HOME}"
  />

  <!-- get Unix hostname, and set to Windows comparable name -->
  <!-- #Trick to get host name x-platform -->
  <property
    name="env.COMPUTERNAME"
    value="${env.HOSTNAME}"
  />

  <!--
    ==========================================================
    Load property files
    Note: the ordering is VERY important.
    ==========================================================
  -->
  <!-- #Allow even users property file to relocate -->
  <property
    name="user.properties.file"
    location="${user.home}/.build.properties"
  />

  <!-- Load the application specific settings -->
  <!-- #Project specific props -->
  <property file="build.properties" />

  <!--
    ==========================================================
    Define your custom properties here.
    You can overwrite them through build.properties and
    ${user.home}/.build.properties
    ==========================================================
  -->

  <property name="myexec1" location="/usr/bin/myexec1"/>
  <property name="myexec2" location="/usr/bin/myexec2"/>

</project>

The important point here is to come up with as many useful default property values ​​as possible, then you can never even create custom files build.properties.

Then you just have <import>this file in your build.xml project.

<project
  name="my-project"
>
  <!-- this is done, so you may import my-project somewhere else -->
  <dirname
    property="my-project.basedir"
    file="${ant.file.my-project}"
  />

  <import file="${my-project.basedir}/relative/path/to/properties.xml"/>

  <target name="using.myexec1">
    <echo message="myexec1=${myexec1}"/>
  </target>
</project>

If you want to create a special value for myexec1 in my-project, just drop the custom flat build.properties file in the same directory as the build.xml file.

The build.properties file may look like this:

myexec1=c:/custom/path/to/myexec1.exe
+1
source

All Articles