You are not logged in.

#1 2018-12-25 21:45:45

Scrumplex
Member
From: Germany
Registered: 2018-12-25
Posts: 6
Website

Forcing java version for building a gradle project

I want to create a PKGBUILD for a Java project. It uses Gradle to compile and only works with Java 11. How can I set the Java version to 11 and compile it with that version?

Offline

#2 2018-12-26 10:01:57

Morganamilo
Package Maintainer (PM)
Registered: 2017-12-05
Posts: 77

Re: Forcing java version for building a gradle project

Depend specifically on java-runtime=11 and build in a clean chroot. This would be the ideal way to go about building. But if you're just asking how to set the java version on your system, see the wiki: https://wiki.archlinux.org/index.php/Ja … etween_JVM

Offline

#3 2018-12-27 22:11:52

Scrumplex
Member
From: Germany
Registered: 2018-12-25
Posts: 6
Website

Re: Forcing java version for building a gradle project

I want my PKGBUILD to be available via the AUR. I am already depending on java-environment=11, but if I run the gradle build it builds it with the system's default JDK. Furthermore I would need to create a startscript which starts the application with Java 11.

Offline

#4 2018-12-27 22:41:50

progandy
Member
Registered: 2012-05-17
Posts: 5,184

Re: Forcing java version for building a gradle project

The section linked by Morganamilo contains "Launching an application with the non-default java version"


| alias CUTF='LANG=en_XX.UTF-8@POSIX ' |

Offline

#5 2018-12-27 23:19:21

Scrumplex
Member
From: Germany
Registered: 2018-12-25
Posts: 6
Website

Re: Forcing java version for building a gradle project

But that relies on a specific version of java. I want to give the user the freedom let them decide for themselves if they want to use Oracle JDK 11 or OpenJDK 11.

Offline

#6 2018-12-28 01:05:27

progandy
Member
Registered: 2012-05-17
Posts: 5,184

Re: Forcing java version for building a gradle project

Then something like this? (untested)

#!/bin/sh

path_prepend_first () {
  export PATH="$1:$PATH"
}
if ! archlinux-java get | grep -q java-11-
then
  path_prepend_first /usr/lib/jvm/java-11-*/jre/bin
fi
exec /path/to/application "$@"

Last edited by progandy (2018-12-28 01:09:42)


| alias CUTF='LANG=en_XX.UTF-8@POSIX ' |

Offline

#7 2018-12-28 02:02:39

eschwartz
Fellow
Registered: 2014-08-08
Posts: 4,097

Re: Forcing java version for building a gradle project

progandy wrote:

Then something like this? (untested)

#!/bin/sh

path_prepend_first () {
  export PATH="$1:$PATH"
}

If $PATH is empty at the time this is function is executed, you will end up with : at the end of your $PATH, which is equivalent to "." and is marginally better at the end of the PATH than at the beginning, but not by much.

if ! archlinux-java get | grep -q java-11-
then
  path_prepend_first /usr/lib/jvm/java-11-*/jre/bin
fi
exec /path/to/application "$@"

Kind of useless use of grep.

#!/bin/sh

# this comes from /etc/profile
prependpath () {
    case ":$PATH:" in
        *:"$1":*)
            ;;
        *)
            export PATH="$1${PATH:+:$PATH}"
    esac
}

case $(archlinux-java get) in
    *java-11*)
        ;;
    *)
        prependpath /usr/lib/jvm/java-11-*/jre/bin
esac

exec /path/to/application "$@"

Managing AUR repos The Right Way -- aurpublish (now a standalone tool)

Offline

Board footer

Powered by FluxBB