Meikel  Brandmeyer avatar Meikel Brandmeyer committed 23505c1

Add ueberjar task in vein of leiningen

[#3 state:resolved tagged:committed]

Comments (0)

Files changed (2)

 ## Clojars Deployment
 
 **Note: Does work only on Unix/Mac OS via shell out to scp. Does not
-work on Windows! Make sure you have agent running which handles your
+work on Windows! Make sure you have an agent running which handles your
 clojars key.**
 
+## Überjars
+
+As Leiningen, Clojuresque now supports überjars. That means you can enable
+the `ueberjar` task with
+
+    ueberjar.enabled = true
+
+Then invoking `gradle ueberjar` will create a jar file with all runtime
+dependencies included.
+
 ## Issues
 
 This is **alpha** software! Expect problems! Please report issues in the
-bugtracker at [the lighthouse tracker][lh].
+bugtracker at [the lighthouse tracker][lh]. Or email them to me.
 
 -- 
 Meikel Brandmeyer <mb@kotka.de>

src/main/groovy/clojuresque/ClojurePlugin.groovy

 import org.gradle.api.plugins.MavenPlugin
 import org.gradle.api.plugins.ProjectPluginsContainer
 import org.gradle.api.tasks.ConventionValue
+import org.gradle.api.tasks.StopExecutionException
 import org.gradle.api.tasks.bundling.Jar
 
 public class ClojurePlugin implements Plugin {
+    public static final String UEBERJAR_TASK_NAME = 'ueberjar'
+
     public void use(Project project, ProjectPluginsContainer handler) {
         JavaPlugin javaPlugin = handler.usePlugin(JavaPlugin.class, project)
         MavenPlugin mavenPlugin = handler.usePlugin(MavenPlugin.class, project)
         configureSourceSetDefaults(project, javaPlugin)
         configureConfigurations(project)
         configureArchives(project)
+        configureUeberjar(project)
     }
 
     private JavaPluginConvention javaConvention(Convention convention) {
 
         project.tasks[JavaPlugin.JAR_TASK_NAME].doFirst(action)
     }
+
+    private void configureUeberjar(Project project) {
+        Jar jar = project.tasks[JavaPlugin.JAR_TASK_NAME]
+        Jar ueberjar = project.tasks.add(UEBERJAR_TASK_NAME, Jar.class)
+
+        ueberjar.configure {
+            description =
+                'Constructs a jar with all runtime dependencies included'
+            dependsOn(jar)
+            baseName = jar.baseName + "-standalone"
+            enabled = false
+            doFirst {
+                if (!jar.enabled)
+                    throw new StopExecutionException("SKIPPED: jar not enabled")
+                project.configurations.runtime.resolve().each {
+                    ueberjar.merge it
+                }
+                ueberjar.merge jar.archivePath
+            }
+        }
+    }
 }
-
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.