Skip to content

Gradle improvements #44

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
May 26, 2019
Merged

Gradle improvements #44

merged 9 commits into from
May 26, 2019

Conversation

wcmatthysen
Copy link
Member

Description of the Change

Made some improvements to the Gradle build script to allow the project to be opened in NetBeans via the Gradle plugin. We can now build the project in NetBeans, run the unit tests, debug it as well as run some of the examples all from NetBeans. The Travis config was also changed to build the project with Gradle.

Why Should This Be In Core?

We want to eventually migrate over to using Gradle as our primary way to build the project. These are some of the necessary changes that we need to make to get there.

Benefits

Easy setup and build of the project in NetBeans (and potentially other IDEs).

Potential Drawbacks

None at this point.

Applicable Issues

Issue #11

If we are going to use gradle to build WorldWind, we need to drop the
NetBeans project folder to prevent NetBeans from thinking this is still
a free-form project. Once removed, and after the Gradle plugin has been
installed in NetBeans, the project will load as a Gradle project.
The wrapper.gradle file determines what version of the gradle-wrapper we
want to use to build the project with. We get the wrapper by running:

`gradle -b wrapper.gradle wrapper`

After which we can build the project with:

`./gradlew clean build`
Made some significant fixes to the build.gradle file:

- To allow this project to open in NetBeans the archiveBaseName variable
  in the extensionsJar-task had to be changed to baseName.
- When you actually try to run one of the example classes in NetBeans
  the resources are not picked up. So, to fix this, the sourceSets' main
  resource clause had to be changed to include the 'src' directory but
  excluding all java source files. We also modified the sourceSets' main
  java clause so that we only include *.java files as sources (else
  resources show up in the source-directory in NetBeans).
- In light of the abovementioned change, the jar and extensionsJar tasks
  were changed. For the jar task, we no longer need to manually include
  the resources as this is now pulled in via the sourceSets. We just
  exclude the 'gov/nasa/worldwindx' folder. A similar change was done
  for the extensionsJar task where we now only have to exclude folders.
  In this case the 'com', 'config', 'images' and 'gov/nasa/worldwind'
  folders to be exact.
- Made a small fix to the compileJava task. To get a debug-build we no
  longer have to specify '-PdebugBuild=true' as an argument for gradle
  when we build. If we want to debug the project in NetBeans, the
  default build should always be a debug-build. Thus we now always build
  a debug-build. However, to now get a release build the compileJava
  task was changed so that we set the options.debug property to false
  when a -PreleaseBuild property is specified.
- Lastly, changed the group to be 'earth.worldwind' as discussed in #36.
- Modified the .gitignore file by adding the .nb-gradle folder as a new
  entry. This is the folder that the NetBeans Gradle plugin produce
  which we can safely ignore from commits. The gradle folder, the
  gradlew and gradlew.bat files were also added as these are produced by
  the gradle-wrapper task and we do not need to keep track of them in
  version-control.
- The bin folder was removed as this is not produced as an output of one
  of the build-tools that we currently use.
- Removed the nbproject/private entry as we no longer load this up as a
  traditional NetBeans free-form project.
Modified the .travis.yml file to allow for Gradle to build the project:

- The first change was adding a call to instantiate the gradle-wrapper
  in the before_install section.
- The install phase now calls the clean-task via the gradle-wrapper.
- The script phase was also changed to call the build and javadoc tasks
  via the gradle-wrapper.
- Gradle writes the javadoc to a 'build/docs' folder instead of the
  'build/doc' folder that ant used. This was changed in the deploy
  section to reflect the gradle folder structure.
Modified the travis.yml file to make use of Java 8 when setting up the
Gradle wrapper. If we do not do this, the build will fail as the
system version of Gradle on Travis is not compatible with Java 11.
Modified the travis.yml file so that Gradle artifacts are cached between
the different builds.
@wcmatthysen wcmatthysen added the enhancement New feature or request label Apr 30, 2019
@wcmatthysen wcmatthysen added this to the WWJ-CE 2.2.0 milestone Apr 30, 2019
@wcmatthysen wcmatthysen requested a review from emxsys April 30, 2019 19:32
@wcmatthysen wcmatthysen self-assigned this Apr 30, 2019
Some remaining changes to the javadocs to fix the OracleJDK11 build.
@robmilton
Copy link

robmilton commented May 17, 2019

@wcmatthysen It looks like the build checks include Oracle and Open JDK 8 and 11. Just wondering why we wouldn't also include Oracle and Open JDK 12 since its general release tool place earlier this year. I don't know that there's a significant amount of change between 11 and 12, but it seems like it might be reasonable to include the latest Java release. Thoughts?

EDIT
I'm not yet familiar with the build testing in GitHub. It dawns on me that these checks may simply be inherited from the project and not specific to this pull request. Is that the case? If so I should direct my question elsewhere...

@wcmatthysen
Copy link
Member Author

@robmilton, I agree. We can probably add it now. In the past we tested against OpenJDK (or OracleJDK) 12 by getting it via openjdk-ea if you look at the Travis-config. Now that it is released, it looks like we can actually add it (see: https://travis-ci.community/t/openjdk-12-no-longer-usable/2718/23). I suppose openjdk-ea will now test against Java 13 early-access releases if I'm not mistaken.

@wcmatthysen
Copy link
Member Author

wcmatthysen commented May 17, 2019

@robmilton, the builds against the different JDKs are as a result of the Travis-config that was inherited from the upstream repository and updated by @emxsys. The travis.yml file indicates to GitHub that we want to build and test the changes in each pull-request on Travis. It is not just specific to this pull-request. Each and every pull-request kicks off a Travis build that compiles WorldWind on the different JDKs and runs the unit tests on all of them as well.

@robmilton
Copy link

@wcmatthysen, thanks for the explanation. I'm learning how all these pieces fit together. I'm hoping to get to a point soon to be able to contribute as well. I'd love to at least support efforts to get WorldWindJava working on Java 9+ (preferably the keeping it up to date with the latest Java release).

@PJHogan
Copy link
Member

PJHogan commented May 17, 2019

Good luck world crew! Making it all work in smooth wonder with the latest!!!

@gbburkhardt
Copy link
Member

@wcmatthysen, thanks for the explanation. I'm learning how all these pieces fit together. I'm hoping to get to a point soon to be able to contribute as well. I'd love to at least support efforts to get WorldWindJava working on Java 9+ (preferably the keeping it up to date with the latest Java release).

We've been using WorldWind with Java 11 for about two months now. There weren't any major problems. Probably the most work that should be down is updating routines that use deprecated methods. For the rest of our application, figuring out how to fit JAXB in took the most effort. But that library isn't used by WorldWind. We're using AdoptOpenJDK 11.03.

@gbburkhardt
Copy link
Member

@wcmatthysen It looks like the build checks include Oracle and Open JDK 8 and 11. Just wondering why we wouldn't also include Oracle and Open JDK 12 since its general release tool place earlier this year. I don't know that there's a significant amount of change between 11 and 12, but it seems like it might be reasonable to include the latest Java release. Thoughts?

EDIT
I'm not yet familiar with the build testing in GitHub. It dawns on me that these checks may simply be inherited from the project and not specific to this pull request. Is that the case? If so I should direct my question elsewhere...

Well, to use the Oracle Java builds, someone might need to come with the USD $40 for the license fee. ;-)

Added openjdk12 as one of the JDKs that Travis should build against.
This comes after the release of Java 12 in March. The openjdk-ea entry
now points to Java 13 early-access builds.
@wcmatthysen
Copy link
Member Author

@emxsys, @gbburkhardt, I think we can merge this. The first Travis-build failed because I erroneously pushed the gradle-improvements branch to this repo instead of my own fork. I then immediately removed the branch from this repo, but this caused the "Travis CI - Branch" build to fail as it couldn't get the branch anymore. After this I pushed the changes to my own fork. You'll see that the "Travis CI - Pull Request" build succeeds. I added openjdk12 as a new entry to build against and it successfully builds against Java 12 which is good news. The build against openjdk-ea (which is Java 13 if I'm not mistaken) fails though and we'll probably need to address this at some point.

@wcmatthysen wcmatthysen merged commit dc63ddc into WorldWindEarth:develop May 26, 2019
@wcmatthysen wcmatthysen deleted the gradle-improvements branch May 26, 2019 09:42
@robmilton
Copy link

@gbburkhardt, I'm excited to hear you've been running WWJ with Java 11 for a while! I'll definitely be interested in pursuing this topic with you in the near future. In addition to the changes to WW I'd be interested to hear how you're handling the runtime since it seems the JRE is no longer available as of Java 11. If you have a distributed application are you using JLink to package the necessary runtime components in your application? Or are you relying on users installing the JDK? Just interested to hear what you're doing.

The other reason for this post is to ask about the gradle build. I just built WWJ-CE for the first time since the NetBeans project folder was removed and the project moved to a gradle build. When I run my application I'm getting errors stating:
java.lang.NoSuchMethodError: java.nio.ByteBuffer.flip()Ljava/nio/ByteBuffer;

I had this EXACT same behavior a number of weeks back when I tried compiling WW with Java 9. A quick search on Google resulted in many hits explaining Java 9 made a change to java.nio.ByteBuffer.flip() which now returns a ByteBuffer where it used to return a Buffer.

I see that build.gradle is setting sourceCompatibility and targetCompatibility to 1.8. But I don't see where the JDK is specified. How can I guarantee with the gradle build that I'm building using JDK 8 and not JDK 9+?

I'm hoping that if I build using JDK 8 it will address this problem...

@robmilton
Copy link

This issue was that the platform being used by the gradle build was JDK 11. I hadn't noticed the "Platform for build scripts" section in "Gradle project". Once I unchecked the "Inherit" checkbox I was able to choose JDK 8 as the build platform. And after I built using JDK 8 the errors went away.

@gbburkhardt
Copy link
Member

@gbburkhardt, I'm excited to hear you've been running WWJ with Java 11 for a while! I'll definitely be interested in pursuing this topic with you in the near future. In addition to the changes to WW I'd be interested to hear how you're handling the runtime since it seems the JRE is no longer available as of Java 11. If you have a distributed application are you using JLink to package the necessary runtime components in your application? Or are you relying on users installing the JDK? Just interested to hear what you're doing.

The other reason for this post is to ask about the gradle build. I just built WWJ-CE for the first time since the NetBeans project folder was removed and the project moved to a gradle build. When I run my application I'm getting errors stating:
java.lang.NoSuchMethodError: java.nio.ByteBuffer.flip()Ljava/nio/ByteBuffer;

I had this EXACT same behavior a number of weeks back when I tried compiling WW with Java 9. A quick search on Google resulted in many hits explaining Java 9 made a change to java.nio.ByteBuffer.flip() which now returns a ByteBuffer where it used to return a Buffer.

I see that build.gradle is setting sourceCompatibility and targetCompatibility to 1.8. But I don't see where the JDK is specified. How can I guarantee with the gradle build that I'm building using JDK 8 and not JDK 9+?

I'm hoping that if I build using JDK 8 it will address this problem...

  • Netbeans will compile WorldWind using the Gradle build files if you install the Gradle plugin, select the 'build.gradle' file, and run the build task:
    image

  • We settled on AdoptOpenJDK and the OpenJ9 JVM for Java 11. There are other choices available. We also needed a JAXB library. We have a custom installer for deploying our WorldWind based application that includes Java and other third party software. We include all required software on our release media that would be needed on a raw Windows 10 machine, and a custom installer that installs all of it.

  • As mentioned, we didn't need to make any changes to the WorldWind code for Java 11. I've just compiled the 'develop' branch successfully with Java 11, using Netbeans 11.0, albeit with deprecation warnings.

  • Netbeans controls the Java version used in the project properties. While the build is being executed, note the first line in the console for the definition of JAVA_HOME.

@gbburkhardt
Copy link
Member

Unfortunately, compiling without errors is not enough. I notice that the WorldWindow and InstallImagery example applications don't completely display correctly with Java 11. There's some work needed there.

@robmilton
Copy link

@gbburkhardt, thanks for sharing that. I am very interested in getting WWJ to a point where it is compatible with the latest Java release. However, I work for a very small company and have an very large backlog of work. So I'm trying to figure out how I can best support WWJ improvements while getting things done for work.

I really appreciate all that you guys have been doing to move WWJ forward.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants