cjstehno / gradle-natives

Gradle plugin to aid in managing native libraries associated with Java-based projects.
http://cjstehno.github.io/gradle-natives/
Apache License 2.0
32 stars 4 forks source link

Still requires Java 8 #9

Closed CptSpaceToaster closed 9 years ago

CptSpaceToaster commented 9 years ago

I think I have everything setup properly, but I'm getting an odd error that seems to relate to mismatched JVM versions:

Build.gradle

plugins {
    id 'com.stehno.natives' version '0.2.1'
}
apply plugin: 'java'
apply plugin: 'application'

mainClassName = "OpenGLTest"

sourceCompatibility = 1.7
version = '1.0.0'

repositories {
    mavenCentral()
}

dependencies {
    compile group: 'org.codehaus.jackson', name: 'jackson-core-asl', version: '1.9.13'
    compile group: 'org.codehaus.jackson', name: 'jackson-mapper-asl', version: '1.9.13'
    compile group: 'org.lwjgl.lwjgl', name: 'lwjgl', version: '2.+'
    //testCompile group: 'junit', name: 'junit', version: '4.11'
}

task wrapper(type: Wrapper) {
    gradleVersion = '2.3'
}

This is what happens in my console

toaster@toaster ~/Github/Lightscreen (master *+)$ java -version
java version "1.7.0_75"
OpenJDK Runtime Environment (IcedTea 2.5.4) (7u75-2.5.4-1~precise1)
OpenJDK 64-Bit Server VM (build 24.75-b04, mixed mode)
toaster@toaster ~/Github/Lightscreen (master *+)$ 
toaster@toaster ~/Github/Lightscreen (master *+)$ gradle --version

------------------------------------------------------------
Gradle 2.3
------------------------------------------------------------

Build time:   2015-02-16 05:09:33 UTC
Build number: none
Revision:     586be72bf6e3df1ee7676d1f2a3afd9157341274

Groovy:       2.3.9
Ant:          Apache Ant(TM) version 1.9.3 compiled on December 23 2013
JVM:          1.7.0_75 (Oracle Corporation 24.75-b04)
OS:           Linux 3.18.1 amd64

toaster@toaster ~/Github/Lightscreen (master *+)$ 
toaster@toaster ~/Github/Lightscreen (master *+)$ gradle --refresh-dependencies

FAILURE: Build failed with an exception.

* What went wrong:
java.lang.UnsupportedClassVersionError: com/stehno/gradle/natives/NativesPlugin : Unsupported major.minor version 52.0
> com/stehno/gradle/natives/NativesPlugin : Unsupported major.minor version 52.0

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

Total time: 5.661 secs

Full stacktrace: https://gist.github.com/CptSpaceToaster/003d66f6f2cc807eb2f2

Any idea what I'm doing wrong?

CptSpaceToaster commented 9 years ago

This might be an issue with Gradle forcing J8, looking into this...

Edit: Yup... Gradle is forcing J8 here.... what a bummer.

Is there another method other than using the pluggins block or downloading and compiling it myself? I suppose I could stash a copy in my git repo, but I'm trying to allow my project to be compiled everywhere on J7, without having too many extra steps in setup.

Edit: Edit: I opened a report on Gradle's Forum: http://discuss.gradle.org/t/gradle-plugins-block-does-not-function-using-java-7/8595

Sorry for the chatter.

CptSpaceToaster commented 9 years ago

Hmmm... sorry for all of the github chatter, but this was my problem: https://github.com/cjstehno/gradle-natives/issues/8

cjstehno commented 9 years ago

No problem. Should this issue be closed or are you still having issues?

CptSpaceToaster commented 9 years ago

Long story short:

  1. I ran into problems, and thought that you had fixed them in issue 8.
  2. I blamed gradle
  3. gradle is fine
  4. Your pluggin still requires J8
cjstehno commented 9 years ago

Gotcha. I will have to dig deeper into it to see what's still using J8. I should be able to look at it this week.

CptSpaceToaster commented 9 years ago

So... when I was trying to get this to work, I just circumvented the pluggin with these two code blocks in my build.gradle:

String os = System.properties['os.name'].toLowerCase()
if (project.hasProperty('os')) {
    os = project.os.toLowerCase()
} else {
    if (os.contains("windows"))
        os = "windows"
    if (os.contains("linux"))
        os = "linux"
    if (os.contains("os x"))
        os = "osx"
}

and

// Add a task to copy the native libraries to the $buildDir/natives/$os directory
task ('installNatives', type: Copy) {
    def artifacts = configurations.compile.resolvedConfiguration.resolvedArtifacts.findAll { it.classifier == "natives-$os" }
    artifacts.each {
        from zipTree(it.file)
    }
    into "$buildDir/natives/$os"
}

// Add the natives lib to the java.library.path for testing
run {
    systemProperty "java.library.path", "$buildDir/natives/$os"
}

run.dependsOn 'installNatives'

I asked gradle where it hid the natives, and then did some OS fuzzing to detect what I'm running on, and where I should copy too. You can override the os using the flag -Pos="linux"

https://github.com/CptSpaceToaster/OpenGL-boiler/blob/master/build.gradle

Thoughts? I think this pluggin might be improved by looking at System.properties['os.name'].toLowerCase()

cjstehno commented 9 years ago

I will look into your suggestions, might make a good default value. Also, I think I have a fix for the Java 8 requirement. I fixed a similar issue at work today which basically comes down to replacing:

compileJava {
    sourceCompatibility = 7
    targetCompatibility = 7
}

with

sourceCompatibility = 7
targetCompatibility = 7

I should be able to test this in the next day or two.

cjstehno commented 9 years ago

@CptSpaceToaster - Please install v0.2.2 when you have a chance and let me know if you continue to have issues. The .class files are reading as 7 now so this should be fixed. The new version is deployed to bintray, but not appearing on the Gradle plugins site yet so you might need to verify the version.

CptSpaceToaster commented 9 years ago

Works!