Assets not being loaded (libGDX) - java

So I've made a small desktop application in Eclipse (gradle project) based on libGDX. Runs perfectly in Eclipse. When I export as a "runnable JAR file" (with Package required libraries into generated JAR checked) I get a warning: "Fat Jar Export: Could not find class-path entry for 'D:Project TI Helper/core/bin/default/".
Is something missing in the manifest at "Class-Path: ." ?
I have no idea what this is about. But the JAR is certainly not runnable. So I try the command prompt and do "gradle desktop:dist --stacktrace". Then the JAR file seems to be produced without any errors or warnings. So I go to .../desktop/build/libs/ and try to run it with "java -jar desktop-1.0.jar", the texture packer starts packing but fails in the end with this message in the console.
The generated atlas-file IS in the specified location. The textures WERE packed. Why on earth is it not loading the stuff?? Btw, I'm using Java version 1.8.0_241 for both JDK and JRE.
EDIT
So it fails in the Assets class at "TextureAtlas atlas = assets2d.get(Cn.TEXTURES);". Going deeper into the AssetManager
public synchronized <T> T get (String fileName) {
Class<T> type = assetTypes.get(fileName);
if (type == null) throw new GdxRuntimeException("Asset not loaded: " + fileName);
...
So it seems the string provided is not pointing to my atlas-file. Cn.TEXTURES is defined as "../desktop/assets/atlas/textures.atlas". That raises the question: How DO you write the path?
DesktopLauncher.java
public class DesktopLauncher
{
public static boolean rebuildAtlas = true;
public static boolean drawDebugOutline = true;
public static void main (String[] arg)
{
// Build Texture Atlases
if (rebuildAtlas) {
Settings settings = new Settings();
settings.maxWidth = 2048;
settings.maxHeight = 2048;
settings.pot = false;
settings.combineSubdirectories = true;
// Pack images in "textures" folder
TexturePacker.process("assets/textures", "assets/atlas", "textures.atlas");
}
LwjglApplicationConfiguration cfg = new LwjglApplicationConfiguration();
cfg.title = "TI Helper";
cfg.useGL30 = false;
cfg.width = Cn.RESOLUTION_WIDTH;
cfg.height = Cn.RESOLUTION_HEIGHT;
cfg.fullscreen = true;
new LwjglApplication(new TIHelper(), cfg);
}
}
Assets.java
public class Assets implements Disposable, AssetErrorListener
{
public static final String TAG = Assets.class.getName();
public static final Assets instance = new Assets();
// Asset managers
public AssetManager assets2d;
public AssetDeco assetDeco;
public AssetFonts fonts;
public AssetMisc assetMisc;
// General fonts
public static Font not16, not20, not24, dig16;
// Singelton: prevent installation from other classes
private Assets() {}
public void init ()
{
// Init 2D graphics manager
init2DAssetManager();
TextureAtlas atlas = assets2d.get(Cn.TEXTURES);
// Cn.TEXTURES == String TEXTURES = "../desktop/assets/atlas/textures.atlas";
// Create game resource objects
fonts = new AssetFonts();
assetDeco = new AssetDeco(atlas);
assetMisc = new AssetMisc(atlas);
// Create fonts
not16 = new Font(Assets.instance.fonts.notalot_16);
not20 = new Font(Assets.instance.fonts.notalot_20);
not24 = new Font(Assets.instance.fonts.notalot_24);
dig16 = new Font(Assets.instance.fonts.digits_16);
}
private void init2DAssetManager()
{
// Create the manager
assets2d = new AssetManager();
// Set asset manager error handler
assets2d.setErrorListener(this);
// Load texture atlas
assets2d.load(Cn.TEXTURES, TextureAtlas.class);
// Start loading assets and wait until finished
assets2d.finishLoading();
// Prompt output
Gdx.app.debug(TAG, "# of assets loaded: " + assets2d.getAssetNames().size);
for (String a : assets2d.getAssetNames())
Gdx.app.debug(TAG, "asset: " + a);
}
#Override
public void dispose ()
{
assets2d.dispose();
}
public void error (String filename, Class<?> type, Throwable throwable) {
Gdx.app.error(TAG, "Couldn't load asset '" + filename + "'", (Exception)throwable);
}
...
Desktop build.gradle
apply plugin: "java"
sourceCompatibility = 1.8
sourceSets.main.java.srcDirs = [ "src/" ]
sourceSets.main.resources.srcDirs = ["../desktop/assets"]
project.ext.mainClassName = "com.ti.desktop.DesktopLauncher"
project.ext.assetsDir = new File("../desktop/assets")
task run(dependsOn: classes, type: JavaExec) {
main = project.mainClassName
classpath = sourceSets.main.runtimeClasspath
standardInput = System.in
workingDir = project.assetsDir
ignoreExitValue = true
}
task debug(dependsOn: classes, type: JavaExec) {
main = project.mainClassName
classpath = sourceSets.main.runtimeClasspath
standardInput = System.in
workingDir = project.assetsDir
ignoreExitValue = true
debug = true
}
task dist(type: Jar) {
manifest {
attributes 'Main-Class': project.mainClassName
}
dependsOn configurations.runtimeClasspath
from {
configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) }
}
with jar
}
dist.dependsOn classes
eclipse.project.name = appName + "-desktop"
Workspace build.gradle
buildscript {
repositories {
mavenLocal()
mavenCentral()
maven { url "https://plugins.gradle.org/m2/" }
maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
jcenter()
google()
}
dependencies {
}
}
allprojects {
apply plugin: "eclipse"
version = '1.0'
ext {
appName = "ti-helper"
gdxVersion = '1.9.10'
roboVMVersion = '2.3.8'
box2DLightsVersion = '1.4'
ashleyVersion = '1.7.0'
aiVersion = '1.8.0'
}
repositories {
mavenLocal()
mavenCentral()
jcenter()
google()
maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
maven { url "https://oss.sonatype.org/content/repositories/releases/" }
}
}
project(":desktop") {
apply plugin: "java-library"
dependencies {
implementation project(":core")
api "com.badlogicgames.gdx:gdx-backend-lwjgl:$gdxVersion"
api "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-desktop"
api "com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-desktop"
api "com.badlogicgames.gdx:gdx-tools:$gdxVersion"
api "com.badlogicgames.gdx:gdx-controllers-desktop:$gdxVersion"
api "com.badlogicgames.gdx:gdx-controllers-platform:$gdxVersion:natives-desktop"
}
}
project(":core") {
apply plugin: "java-library"
dependencies {
api "com.badlogicgames.gdx:gdx:$gdxVersion"
api "com.badlogicgames.gdx:gdx-box2d:$gdxVersion"
api "com.badlogicgames.gdx:gdx-controllers:$gdxVersion"
api "net.dermetfan.libgdx-utils:libgdx-utils:0.13.4"
api "net.dermetfan.libgdx-utils:libgdx-utils-box2d:0.13.4"
}
}
If someone could help me out it would much appreciated. This is my first project in libGDX and I'm very stuck here, and I'm all out of ideas on how to find any clues to what might be wrong.

I just had the same issue and removing the ".atlas" from the filename fixed it. Although that is the file type, when I open my atlas file's properties in Windows explorer, the file type is simply listed as "file" rather than atlas.

Related

ClassNotFoundException When running jar file but runs fine in Intellij

I created a small mqtt application using eclipse paho mqtt library in kotlin with Gradle in Intellij IDE. it runs fine when running it through Intellij but when I build it and run the jar file that gets created I get a NoClassDefFoundError error.
From other questions I have seen about this it looks like it has something to do with the class path but I am not sure what needs to be done if that is indeed the issue because I am using gradle and not jar files for libraries.
I was following this tutorial
Here is my gradle file
plugins {
id 'org.jetbrains.kotlin.jvm' version '1.4.31'
id 'application'
}
group = 'me.package'
version = '1.0-SNAPSHOT'
repositories {
mavenCentral()
maven {
url "https://repo.eclipse.org/content/repositories/paho-snapshots/"
}
}
dependencies {
implementation 'org.eclipse.paho:org.eclipse.paho.client.mqttv3:1.2.5'
testImplementation 'org.jetbrains.kotlin:kotlin-test-junit'
}
test {
useJUnit()
}
compileKotlin {
kotlinOptions.jvmTarget = '1.8'
}
compileTestKotlin {
kotlinOptions.jvmTarget = '1.8'
}
application {
mainClassName = 'com.publisher.MainKt'
}
tasks.jar {
manifest {
attributes 'Main-Class': 'com.publisher.MainKt'
}
from {
configurations.compile.collect {
it.isDirectory() ? it : zipTree(it)
}
}
}
And my MainKt file
package com.publisher
import org.eclipse.paho.client.mqttv3.*
import org.eclipse.paho.client.mqttv3.persist.MemoryPersistence
import java.io.File
fun main(args: Array<String>) {
val client = MqttClient("tcp://192.168.0.55:1883","publisher", MemoryPersistence())
val connOpts = MqttConnectOptions()
connOpts.isCleanSession = false
connOpts.isAutomaticReconnect = true
client.setCallback(object: MqttCallback {
override fun connectionLost(cause: Throwable?) {
println("Connection lost")
println(cause!!.message)
}
override fun messageArrived(topic: String?, message: MqttMessage?) {
println("Message Received for topic: $topic")
println("Message: ${message!!.payload}")
}
override fun deliveryComplete(token: IMqttDeliveryToken?) {
println("Message delivered")
}
})
try{
client.connect(connOpts)
println("Connected")
client.subscribe("config/+", 1) { topic, message ->
println("Getting configuration for $message")
val path = System.getProperty("user.dir")
val file = File("$path/${message}.json")
if(file.exists()){
client.publish("/devices/ + $message + /config", MqttMessage(file.readBytes()))
}
}
}catch (e: MqttException){
println("Error: ${e.localizedMessage}")
e.printStackTrace()
}
}
The way you start your application does not include the dependencies, meaning your MQTT driver and the Kotlin dependencies are not included.
Do the following:
gradle distZip
# alternatively
gradle distTar
This will create a zip/tar file containing all the dependencies and a start script. Use that to start your application.
You could consider the Shadow plugin, as it is straightforward to use. Your build.gradle would look something like this:
plugins {
id 'org.jetbrains.kotlin.jvm' version '1.4.31'
// Shadow plugin
id 'com.github.johnrengelman.shadow' version '6.1.0'
id 'java'
}
group = 'me.package'
version = '1.0-SNAPSHOT'
repositories {
mavenCentral()
maven {
url "https://repo.eclipse.org/content/repositories/paho-snapshots/"
}
}
dependencies {
implementation 'org.eclipse.paho:org.eclipse.paho.client.mqttv3:1.2.5'
testImplementation 'org.jetbrains.kotlin:kotlin-test-junit'
}
test {
useJUnit()
}
compileKotlin {
kotlinOptions.jvmTarget = '1.8'
}
compileTestKotlin {
kotlinOptions.jvmTarget = '1.8'
}
application {
mainClassName = 'com.publisher.MainKt'
}
tasks.jar {
manifest {
attributes 'Main-Class': 'com.publisher.MainKt'
}
}
So your fat JAR is generated in the /build/libs directory with all the dependencies included.

How to include the client from openapi-generator in a gradle java application?

I want to create a gradle java application that generates a client from an openAPI specification file and uses that client.
So I created a java application with gradle init (type:application, language:Java, DSL:groovy, test-framework:Junit Jupiter, project-name:simple-java-app, package-structure:a.aa).
Small example of what works:
I can create a new source folder second/loc/src/main/java with a package b.bb and a class Foo.
And with the following build.gradle
plugins {
id 'java'
id 'application'
}
repositories {
jcenter()
}
sourceSets {
second {
java {
srcDir 'second/loc/src/main/java'
}
}
}
compileJava {
source += sourceSets.second.java
}
dependencies {
implementation 'com.google.guava:guava:29.0-jre'
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.6.2'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.6.2'
}
application {
mainClassName = 'a.aa.App'
}
test {
useJUnitPlatform()
}
The main class can access Foo:
package a.aa;
import b.bb.Foo;
public class App {
public static void main(String[] args) {
System.out.println(new Foo().sayFoo());
}
}
What doesn't work
Now I try the same for generated code by openapi-generator:
Under plugins I add id "org.openapi.generator" version "4.3.1"
And I add a new task:
openApiGenerate {
generatorName = "java"
inputSpec = "$rootDir/specs/petstore.yaml".toString()
outputDir = "$buildDir/generated".toString()
apiPackage = "org.openapi.example.api"
invokerPackage = "org.openapi.example.invoker"
modelPackage = "org.openapi.example.model"
configOptions = [
dateLibrary: "java8"
]
}
Then I execute the task openApiGenerate and confirm in the file system that the sources have been generated(eclipse won't show the build folder).
Now I use the same method as above resulting in below build.gradle
plugins {
id 'java'
id 'application'
id "org.openapi.generator" version "4.3.1"
}
repositories {
jcenter()
}
openApiGenerate {
generatorName = "java"
inputSpec = "$rootDir/specs/petstore.yaml".toString()
outputDir = "$buildDir/generated".toString()
apiPackage = "org.openapi.example.api"
invokerPackage = "org.openapi.example.invoker"
modelPackage = "org.openapi.example.model"
configOptions = [
dateLibrary: "java8"
]
}
sourceSets {
client {
java {
srcDir '$buildDir/generated/src/main/java'
}
}
}
compileJava {
source += sourceSets.client.java
}
dependencies {
implementation 'com.google.guava:guava:29.0-jre'
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.6.2'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.6.2'
}
application {
mainClassName = 'a.aa.App'
}
test {
useJUnitPlatform()
}
But when I try to use the classes now:
package a.aa;
import org.openapi.example.model.Pet;
public class App {
public static void main(String[] args) {
Pet p = new Pet(0L);
System.out.println(p.getId());
}
}
neither import nor Pet can be resolved.
> Task :compileJava FAILED
C:\...\simple-java-app\src\main\java\a\aa\App.java:6: error: package org.openapi.example.model does not exist
import org.openapi.example.model.Pet;
^
C:\...\simple-java-app\src\main\java\a\aa\App.java:14: error: cannot find symbol
Pet p = new Pet(0);
^
symbol: class Pet
location: class App
C:\...\simple-java-app\src\main\java\a\aa\App.java:14: error: cannot find symbol
Pet p = new Pet(0);
^
symbol: class Pet
location: class App
3 errors
FAILURE: Build failed with an exception.
I don't know how to debug this, frankly I'm unsure if source sets are even the right way. All openapi-generator tutorials seem to use them, I haven't tried subprojects yet, the openApiGenerate task seems to create a complete project with build.gradle and everything.
You need to add the sources from the generated code to your project. One example from one of my projects:
sourceSets.main.java.srcDir "${buildDir}/generated/src/main/java"
After generation make sure you refresh gradle and project.
With build.gradle.kts and gradle 7+ I used in Kotlin DSL:
configure<SourceSetContainer> {
named("main") {
java.srcDir("$buildDir/generated/src/main/java")
}
}
To add the java generated sources to the project's source.

JNI Error - libGDX ApplicationListener not found

So I've just exported my project as a JAR-file. I'm only making a desktop application. When trying to run the program i get
"A JNI error has occurred.." Not much else there. However, in the command prompt it is revealed that
"Exception in thread "main" java.lang.NoClassDefFoundError: com/badlogic/gdx/ApplicationListener"
So the libGDX ApplicationListener can't be found? It works perfectly when compiling/running in Eclipse.
I'm using:
Windows 7 Ultimate
Eclipse Oxygen.3a
Gradle 4.4.1
java JRE version 1.8.0_241
java JDK version 1.8.0_241
Environment variables:
PATH_HOME: "C:\Program Files\Java\jdk1.8.0_241"
var: "C:\Program Files\Java\jdk1.8.0_241\bin"
Path: "C:\Program Files (x86)\Common Files\Oracle\Java\javapath; C:\ProgramData\Oracle\Java\javapath; C:\Windows\system32; C:\Windows; C:\Windows\System32\Wbem; C:\Windows\System32\WindowsPowerShell\v1.0\; C:\Gradle\gradle-4.4.1\bin"
Main class
public class DesktopLauncher
{
public static boolean rebuildAtlas = true;
public static boolean drawDebugOutline = true;
public static void main (String[] arg)
{
// Build Texture Atlases
if (rebuildAtlas) {
Settings settings = new Settings();
settings.maxWidth = 1024;
settings.maxHeight = 1024;
settings.combineSubdirectories = true;
// Pack images in "textures" folder
TexturePacker.process("assets/textures", "assets/atlas", "textures.atlas");
}
LwjglApplicationConfiguration cfg = new LwjglApplicationConfiguration();
cfg.title = "TI Helper";
cfg.useGL30 = false;
cfg.width = Cn.RESOLUTION_WIDTH;
cfg.height = Cn.RESOLUTION_HEIGHT;
cfg.fullscreen = true;
new LwjglApplication(new ti_app(), cfg);
}
}
Desktop build.gradle
apply plugin: "java"
sourceCompatibility = 1.8
sourceSets.main.java.srcDirs = [ "src/" ]
sourceSets.main.resources.srcDirs = ["../core/assets"]
project.ext.mainClassName = "com.lf.desktop.DesktopLauncher"
project.ext.assetsDir = new File("../core/assets")
task run(dependsOn: classes, type: JavaExec) {
main = project.mainClassName
classpath = sourceSets.main.runtimeClasspath
standardInput = System.in
workingDir = project.assetsDir
ignoreExitValue = true
}
task debug(dependsOn: classes, type: JavaExec) {
main = project.mainClassName
classpath = sourceSets.main.runtimeClasspath
standardInput = System.in
workingDir = project.assetsDir
ignoreExitValue = true
debug = true
}
task dist(type: Jar) {
manifest {
attributes 'Main-Class': project.mainClassName
}
dependsOn configurations.runtimeClasspath
from {
configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) }
}
with jar
}
dist.dependsOn classes
Core build.gradle
apply plugin: "java"
sourceCompatibility = 1.8
[compileJava, compileTestJava]*.options*.encoding = 'UTF-8'
sourceSets.main.java.srcDirs = [ "src/" ]
Workspace build.gradle
buildscript {
repositories {
mavenLocal()
mavenCentral()
maven { url "https://plugins.gradle.org/m2/" }
maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
jcenter()
google()
}
dependencies {
}
}
allprojects {
apply plugin: "eclipse"
version = '1.0'
ext {
appName = "TIHelper"
gdxVersion = '1.9.10'
roboVMVersion = '2.3.8'
box2DLightsVersion = '1.4'
ashleyVersion = '1.7.0'
aiVersion = '1.8.0'
}
repositories {
mavenLocal()
mavenCentral()
jcenter()
google()
maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
maven { url "https://oss.sonatype.org/content/repositories/releases/" }
}
}
project(":desktop") {
apply plugin: "java-library"
dependencies {
implementation project(":core")
api "com.badlogicgames.gdx:gdx-backend-lwjgl:$gdxVersion"
api "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-desktop"
api "com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-desktop"
api "com.badlogicgames.gdx:gdx-tools:$gdxVersion"
api "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-desktop"
api "com.badlogicgames.gdx:gdx-bullet-platform:$gdxVersion:natives-desktop"
}
}
project(":core") {
apply plugin: "java-library"
dependencies {
api "com.badlogicgames.gdx:gdx:$gdxVersion"
api "com.badlogicgames.gdx:gdx-box2d:$gdxVersion"
api "com.badlogicgames.gdx:gdx-freetype:$gdxVersion"
api "com.badlogicgames.gdx:gdx-bullet:$gdxVersion"
api "com.badlogicgames.box2dlights:box2dlights:$box2DLightsVersion"
api "com.badlogicgames.gdx:gdx-ai:$aiVersion"
api "net.dermetfan.libgdx-utils:libgdx-utils:0.13.4"
api "net.dermetfan.libgdx-utils:libgdx-utils-box2d:0.13.4"
api "com.badlogicgames.ashley:ashley:$ashleyVersion"
}
}
Singular unsettling tales also suggests I could be missing some sort of native JAR-file (gdx-native.jar or something like that) among my external dependencies
But those topics where years of age so I guess I have it, it's just named "gdx-platform-1.9.10-natives-desktop.jar" nowadays. Or is the problem related to the fact that the project says Native library location: (none)? I'm kinda lost here I must say. Are the libGDX jars not exported?

image chooser javafx android mobile

How to choose image from android directory/gallery in javafxmobile-plugin. I am unable to choose files like images in android device. when i open directory app hangs and suddenly close. Any help???
I already have tried in android device using javafx file chooser && directory choose but notthing helps. also i found no helpful post on the stackoverflow
my build.gradle file:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'org.javafxports:jfxmobile-plugin:1.3.16'
}
}
apply plugin: 'org.javafxports.jfxmobile'
repositories {
jcenter()
maven {
url 'http://nexus.gluonhq.com/nexus/content/repositories/releases'
}
}
mainClassName = 'com.maqboolsolutions.directorychooserandroid.App'
ext.CHARM_DOWN_VERSION = "1.0.0"
dependencies {
compile "com.gluonhq:charm-down-common:$CHARM_DOWN_VERSION"
desktopRuntime "com.gluonhq:charm-down-desktop:$CHARM_DOWN_VERSION"
androidRuntime "com.gluonhq:charm-down-android:$CHARM_DOWN_VERSION"
compile 'com.airhacks:afterburner.mfx:1.6.3'
}
jfxmobile {
javafxportsVersion = '8.60.11'
android {
manifest = 'src/android/AndroidManifest.xml'
packagingOptions {
exclude 'META-INF/INDEX.LIST'
}
dexOptions {
javaMaxHeapSize "4g"
}
}
}
.java codding:
#FXML
private void btnCooserOnAction(ActionEvent event) {
DirectoryChooser directoryChooser = new DirectoryChooser();
Stage primaryStage = (Stage) stackPaneRoot.getScene().getWindow();
File selectedDirectory = directoryChooser.showDialog(primaryStage);
if (selectedDirectory == null) {
lblPath.setText("No Directory selected");
} else {
lblPath.setText(selectedDirectory.getAbsolutePath());
}
}
App not response. and close...

Gradle Plugin/Task evaluated before build

One of my plugins uses the files created by the gradle build of another project.
However gradle evaluates the plugin task before building. Is there a way to make the plugin tasks be created after the build is completed?
EDIT:
Here is the build.gradle
apply plugin: 'confluence-export'
sourceSets {
tools
}
compileToolsJava {
source += sourceSets.main.java
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
dependencies {
toolsCompile files("${System.getProperty('java.home')}/../lib/tools.jar")
}
task generateTagDoc(type: JavaExec) {
classpath = sourceSets.tools.runtimeClasspath
main = 'TagsDocumentation'
outputs.upToDateWhen { false }
}
task generateTypeDoc(type: Javadoc) {
classpath = sourceSets.tools.runtimeClasspath
source = sourceSets.main.allJava
options.docletpath = compileToolsJava.outputs.files.asList()
options.doclet = "ExtractCommentsDoclet"
options.addStringOption("Tags.java")
outputs.upToDateWhen { false }
}
confluence {
spaceKey = *****
exportAll = true
title = *******
exportUser = "******
exportPassword = ******
libraryName = ******
host = ********
}
asciidoctor {
resources {
from(sourceDir) {
include 'img/**'
}
}
}
asciidoctor.dependsOn(generateTagDoc)
generateTagDoc.dependsOn(generateTypeDoc)
generateTypeDoc.dependsOn(compileToolsJava)
So here I want my build to run which will create a folder asciidoc/html5 in the build folder with all my created html pages from my asciidoc files. My plugin goes through each file and creates a task for it and then uploads it to a website. The problem is the plugin task is evaluated before the build so the folder asciidoc/html5 hasn't been created yet. If i add a check to see if the folder has been created it will indeed remove my error however the task will still be empty. This is why i would like to know if there is a way for the plugin tasks to be created after the build is done so that the folder is created.
EDIT 2:
Here is the plugin creation:
class ConfluenceExportPlugin extends ConfluencePluginBase implements Plugin<Project> {
#Override
void apply(Project project) {
def confluenceExtension = project.extensions.create('confluence', ConfluenceExtension)
project.afterEvaluate {
if (confluenceExtension.exportAll) {
def list = []
def dir = new File("${project.buildDir}/asciidoc/html5")
if(dir.exists() && dir.isDirectory())
dir.eachFileRecurse(FileType.FILES) {
if(it.name.endsWith('.html')) {
list.add(it)
}
}
Task mainTask = project.task('confluenceExport')
mainTask.dependsOn("build")
list.each { file ->
def curName = file.name.take(file.name.lastIndexOf('.'))
ConfluenceExportTask subTask = createTask(project, "confluenceExport${curName}", confluenceExtension, file.path, curName)
mainTask.dependsOn(subTask)
}
}
else {
ConfluenceExportTask task = createTask(project, "confluenceExport", confluenceExtension, getManFile(confluenceExtension, project), confluenceExtension.title)
}
}
}
ConfluenceExportTask createTask(Project project, String taskName, def confluenceExtension, manFile, String pageTitle ){
ConfluenceExportTask task = project.task(type: ConfluenceExportTask, taskName)
task.conventionMapping.map "user", { confluenceExtension.user }
task.conventionMapping.map "password", { confluenceExtension.password }
task.conventionMapping.map "spaceKey", { confluenceExtension.spaceKey }
task.conventionMapping.map "manFile", { manFile }
task.conventionMapping.map "pageTitle", { pageTitle }
task
}
String getManFile(ConfluenceExtension configuration, Project project) {
configuration.exportSourceFilePath ?: "${project.buildDir}/asciidoc/html5/${configuration.libraryName}.html"
}
}

Categories

Resources