crotwell / gradle-macappbundle

A Gradle Plugin to create a Mac OSX .app application and dmg based on the project.
Apache License 2.0
94 stars 33 forks source link

Copy resources on build like "classpath" option in ant bundleapp task #45

Open radistao opened 7 years ago

radistao commented 7 years ago

Hi crotwell.

I assemble Mac OS .app application and now trying to switch from ant bundler task to your gradle one. In the ant task i have the next settings, which i can't find in your implementation:

<target name="bundleMac" depends="cleanTarget, checkProperties">
    <taskdef name="bundleapp"
           classname="com.oracle.appbundler.AppBundlerTask"
           classpath="${basedir}/lib/appbundler-1.0.jar"/>

     <bundleapp >

         <classpath file="${buildDir}/libs/BuildUberJar.jar"/>
         <classpath file="${libDir}/lib.dylib"/>
         <classpath file="${libDir}/license.txt"/>
         <classpath file="${resDir}/${splashImagePath}"/>

this classpath property copies files from build resources to Contents/Java bundled directory and would be used by the application at runtime.

There are 2 problems i see:

  1. Instead of just putting my single über-jar to Java directory it puts all the dependencies jars.
  2. I've not found a way to copy resources (like those dylib, txt and splash image) to Java directory.
  3. When i build using this ant task in the result Content directory also Resources subdirectory exists with my '128.icns' and some default en.lproj/Localizable.strings messages ("JRELoadError", "MainClassNameRequired", "JavaDirectoryNotFound"). Why it's absent in this gradle task?

See the classpath description in (AppBundler documentation)[https://java.net/downloads/appbundler/appbundler.html]

Thanks.

gravelld commented 7 years ago

I've noticed this too. I need a way of controlling the classpath; dumping all the runtime dependencies into Java/ won't work for me because of various classloader things going on in my app...

crotwell commented 7 years ago

For 1, I can look into this a bit. I think the right answer is to make the configuration used by the plugin configurable instead of using always using the runtime configuration.

For 2 and 3, you can create your own copy task to put whatever you want into the app dir. Just make your Copy task depend on generatePlist and make the createApp task depend on it so it is in the right order. There is already something to handle icons, but you need set the icon property in your macAppBundle config.

crotwell commented 7 years ago

I believe this is resolved with this commit.

Also have added a wiki page with how to use a configuration with a uberjar, using the shadow plugin as an example

Please have a look and let me know if this takes care of your issue.

gravelld commented 7 years ago

So my requirement was partly because of me learning Gradle at the same time I think. I had this build inside the project which contained the Main class, thus the Gradle task inherited the dependencies.

When I split it out into a separate build project I had more control over the dependencies, and as you say @crotwell I was able to just perform copies to get the directories looking how I liked them.

One nuisance is that a JAR file for the build project always seems to be generated. This is empty, because the build project isn't a Java one. I just delete it in doLast.

radistao commented 7 years ago

For 2 and 3, you can create your own copy task to put whatever you want into the app dir. Just make your Copy task depend on generatePlist and make the createApp task depend on it so it is in the right order. There is already something to handle icons, but you need set the icon property in your macAppBundle config.

I'm just confused why the plugin can't be created "all in one" and repeat/extend functionality of the original ant bundle task? Why we are going on way of reducing, instead of extending?

I believe that the main goal of any plugin is to reduce amount of manual job. Basically, any gradle plugin may be exchanged with own copy/exec/unzip/whatever task, but instead of that we create plugins to simplify some standard actions.

I'd like to help to extend this functionality if you agree you'll accept the fix. The only one limit - this will take a while cos i'm not familiar with groovy, at least i'd appreciate any examples/guides/references i can follow to implement the functionality in the shortest way. Thanks.

crotwell commented 7 years ago

The short answer is that this plugin existed before the AppBundlerTask. I wrote this back when Apple was responsible for Java on the Mac, and then extended it to work with Oracle Java on the Mac when that transition happened.

I will have a look at what the app bundler does. I am not interested in compatibility with that ant task "just because". But if those files are needed to run a java app on the mac correctly, then I would like to make sure they are there. But I have not seen a case where the fact that they were not there caused a problem. Do you believe that they are really needed?

radistao commented 7 years ago

for sure: i create an application which used at runtime *.dlyb.

Second issue: splash screen during an application run should be specified as a path to an existent image (see http://stackoverflow.com/questions/23001292/animated-gif-leads-to-splashscreen-being-null and http://stackoverflow.com/questions/4964397/mac-os-java-splash/8829400#8829400)

Basically, the reason i created this issue: i'm trying to switch from ant task to completely gradle one, and i'm missing exactly this functionality of the native ant task, that's why i still run the ant task from my gradle script, which looks lame ((

Here is the bundler page and doc: https://java.net/projects/appbundler

https://java.net/downloads/appbundler/appbundler.html

catadincu commented 6 years ago

Are there plans to release the 2.1.7 version including the uberjar functionality in the near future to the Gradle plugins repository?

crotwell commented 6 years ago

Released 2.1.7 today, thanks for the reminder.