0

Background

I've spent quite a lot of time re-setting-up the build process for a project that has been dormant for several months. This is a project written for Java 8. The output is a single JAR archive. The build output is defined in File / Project Structure / Project Settings / Artifacts, see screenshot. To build, I use Build / Build artifacts.

enter image description here

This GUI appears to be translated into the following config files:

ifos_repo/.idea/artifacts/iFOS_jar.xml

<component name="ArtifactManager">
  <artifact type="jar" name="iFOS:jar">
    <output-path>$PROJECT_DIR$/out/artifacts/iFOS_jar</output-path>
    <root id="archive" name="iFOS.jar">
      <element id="directory" name="META-INF">
        <element id="file-copy" path="$PROJECT_DIR$/META-INF/MANIFEST.MF" />
      </element>
      <element id="module-output" name="iFOS.main" />
      <element id="module-source" name="iFOS.main" />
      <element id="file-copy" path="$PROJECT_DIR$/src/main/resources/splash.png" />
    </root>
  </artifact>
</component>

ifos_repo/build.gradle

apply plugin: 'idea'
apply plugin: 'java'


tasks.withType(JavaCompile) {
    options.encoding = 'UTF-8'
}

jar {
    manifest {
        attributes(
            'Main-Class': 'za.co.iFos.IFos',
            "Class-Path": '. lib/jssc-2.5.0-src.jar lib/jssc.jar lib/commons-jexl-2.1.1.jar lib/commons-logging-1.2.jar lib/SteelSeries.jar lib/trident-6.3.jar lib/openmap.jar lib/commons-lang3-3.4.jar lib/CANBabel-2.0-jar-with-dependencies.jar'
        )
        exclude 'META-INF/*.DSA', 'META-INF/*.RSA', 'META-INF/*.SF'
    }
    //from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
}

group 'za.co.iFos'

sourceCompatibility = 1.8

repositories {
    mavenCentral()
    flatDir {
        dirs 'lib'
    }
}

dependencies {
    compile fileTree(dir: 'lib', include: '*.jar')
    testCompile group: 'junit', name: 'junit', version: '4.12'

    compile group: 'jfree', name: 'jfreechart', version: '1.0.12'
}

Issue

Everything works except for one nuisance: The output JAR file only has read/write permissions but not the executable permission. So I have to manually go into the file properties / permissions tab and tick "Allow this file to run as a program". I would like to have this set automatically during the build process with IntelliJ IDEA & Gradle.

How can I set the executable bit automatically at the end of the build process?

What I've researched

I've looked at this popular question with a similar title but it is not about the executable permission at all.

The answers to this question about setting the executable bit in Gradle appears to have the way forward. However I haven't figured out what to use for the file path – with '$PROJECT_DIR$/out/artifacts/iFOS_jar' it doesn't work. I'm also not sure, if it's okay to mess with build.gradle or whether this fill will be overwritten by the GUI anyways the next time I change something.

Joooeey
  • 3,394
  • 1
  • 35
  • 49

0 Answers0