# Updating P3 library for P4

**URL:** https://discourse.processing.org/t/updating-p3-library-for-p4/32191
**Category:** Development
**Created:** [September 10, 2021, 11:12pm UTC](https://discourse.processing.org/t/updating-p3-library-for-p4/32191 "2021-09-10T23:12:48Z")
**Posts on this page:** 11
**Page:** 1

<div class="post-metadata">

### Author: ![robertesler](https://avatars.discourse-cdn.com/v4/letter/r/ec9cab/32.png) [@robertesler](https://discourse.processing.org/u/robertesler)
#### Post date: [September 10, 2021, 11:12pm UTC](https://discourse.processing.org/t/updating-p3-library-for-p4/32191/1 "2021-09-10T23:12:48Z")

</div>

Does anyone know if there is, or will be, a way to distribute different versions of a library for P3 and P4. Right now my own library, and others I use, works in P4 but are compiled for Java 8. Can we have two versions, one compiled in Java 8 and one in Java 11?

Right now it seems that if I update to Java 11 for P4 it would break the lib in P3. Does anyone have an idea of how to handle this moving forward?

---

<div class="post-metadata">

### Author: ![neilcsmith](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/neilcsmith/32/144_2.png) [@neilcsmith](https://discourse.processing.org/u/neilcsmith)
#### Post date: [September 11, 2021, 11:50am UTC](https://discourse.processing.org/t/updating-p3-library-for-p4/32191/2 "2021-09-11T11:50:14Z")

</div>

> [@robertesler](#):
>
> works in P4 but are compiled for Java 8.

So, what problem are you trying to solve that you don’t seem to have?

Incidentally, if you really wanted to target some optional things at Java 11+, you could read up on multi-release JARs, but I doubt it’s worth the hassle.

I wonder when Processing will support Java 17 that’s released next week? 😄

---

<div class="post-metadata">

### Author: ![robertesler](https://avatars.discourse-cdn.com/v4/letter/r/ec9cab/32.png) [@robertesler](https://discourse.processing.org/u/robertesler)
#### Post date: [September 11, 2021, 3:32pm UTC](https://discourse.processing.org/t/updating-p3-library-for-p4/32191/3 "2021-09-11T15:32:30Z")

</div>

Hi @neilcsmith, I guess I’m asking about backwards compatibility for libraries between P3 and P4. Was this an issue with P2 and P3? Eventually library developers will want to use Java 11 so we would have to keep either a separate repository or have two versions of our build script so P3 users could manually compile the library.  
For me it’s about the speed difference in Java 11. So I guess I could build two versions and have instructions on how to manually install one or the other. I’m wondering what other developers are planning to do to stay compatible for the immediate future.

---

<div class="post-metadata">

### Author: ![neilcsmith](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/neilcsmith/32/144_2.png) [@neilcsmith](https://discourse.processing.org/u/neilcsmith)
#### Post date: [September 11, 2021, 3:52pm UTC](https://discourse.processing.org/t/updating-p3-library-for-p4/32191/4 "2021-09-11T15:52:00Z")

</div>

> [@robertesler](#):
>
> For me it’s about the speed difference in Java 11.

Speed difference of what?! Java 8 compatible code should run just as fast as Java 11 code on a Java 11 JVM.

I agree, at some point if you want to make use of new Java language or library features, then you might look to drop Java 8 support. But is there any reason you need to rush that now? I don’t produce any Processing libraries directly, but I do maintain libraries used in the Video library, and we’re certainly not dropping Java 8 support in the near future.

If you’re compiling on JDK 11+, make sure you’re using the new `--release` option to keep everything compatible with JDK 8.

---

<div class="post-metadata">

### Author: ![hamoid](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/hamoid/32/58_2.png) [@hamoid](https://discourse.processing.org/u/hamoid)
#### Post date: [September 12, 2021, 4:03pm UTC](https://discourse.processing.org/t/updating-p3-library-for-p4/32191/5 "2021-09-12T16:03:18Z")

</div>

After a few days twisting Gradle to build the Video Export Library I got it to work!!! 🙂 Happy about it.

It seems to run in Processing 3 and Processing 4. I run the task called `shadow/shadowJar` to build it.

It’s now written in Kotlin. Missing still is to copy some files, documentation, examples. Maybe figure out how to write some tests which produce video files and extract metadata from the resulting mp4’s to see if the files look correct.

## build.gradle.kts

```gradle
plugins {
    id("org.jetbrains.kotlin.jvm") version "1.5.0"
    id("org.jetbrains.dokka") version "1.5.0"
    id("com.github.johnrengelman.shadow") version "7.0.0"
    `java-library`
}

repositories {
    mavenCentral()
    maven {
        url = uri("https://jitpack.io")
    }
}

dependencies {
    // Align versions of all Kotlin components
    implementation(platform("org.jetbrains.kotlin:kotlin-bom"))
    implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")

    // used internally, not exposed to consumers on their own compile classpath
    //implementation("org.processing:core:3.3.7")
    //implementation("org.processing:pde:3.3.7")
    compileOnly("com.github.micycle1:processing-core-4:4.0.3")

    compileOnly("net.java.dev.jna:jna:5.7.0")
    compileOnly("net.java.dev.jna:jna-platform:5.7.0")

    // Test
    testImplementation("org.jetbrains.kotlin:kotlin-test")
    testImplementation("org.jetbrains.kotlin:kotlin-test-junit")
    testImplementation("org.processing:core:3.3.7")

    // Documentation
    dokkaHtmlPlugin("org.jetbrains.dokka:kotlin-as-java-plugin:1.5.0")

    // Exported to consumers
    //api("org.apache.commons:commons-math3:3.6.1")
}

tasks.jar {
    manifest {
        attributes(
            mapOf(
                "Implementation-Title" to project.name,
                "Implementation-Version" to project.version
            )
        )
    }

    doLast {
        copy {
            from(layout.buildDirectory.dir("libs/${rootProject.name}-all.jar"))
            into("/home/funpro/Desktop/edu/src/processing/libraries" +
                    "/videoExport/library/")
        }
    }
}

```

I’ll release it soon. I also could share the whole template to create a Processing Library with Kotlin and Gradle (and IntelliJ?). I guess using Java would require few or no changes.

ps. found the maven artifact in [Processing 4 Core Maven Artifact - #8 by monkstone](https://discourse.processing.org/t/processing-4-core-maven-artifact/27334/8)

---

<div class="post-metadata">

### Author: ![robertesler](https://avatars.discourse-cdn.com/v4/letter/r/ec9cab/32.png) [@robertesler](https://discourse.processing.org/u/robertesler)
#### Post date: [September 13, 2021, 10:59pm UTC](https://discourse.processing.org/t/updating-p3-library-for-p4/32191/6 "2021-09-13T22:59:26Z")

</div>

Thanks @hamoid for the Maven example. I haven’t used Maven for P3 yet, but have for other things. I’ll look at it.

I have found at least for my library about 12-14% drop in performance from P3 to P4. P3 seems to run a bit faster. But if I build it using only JDK11 (no JDK8 support) in P4 that drop mostly goes away. This is what prompted my question. But perhaps others are not experiencing this with their libs.

My lib uses the JNI heavily and the backend is in C++ so perhaps that is another reason for a performance drop between versions. I really don’t know.

So I suppose unless I figure something else out, I guess I could include a JDK11 build with the distro and have instructions on how P4 users could manually implement it. Then when P3 becomes out of fashion do the opposite.

Thanks for the feedback.

---

<div class="post-metadata">

### Author: ![hamoid](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/hamoid/32/58_2.png) [@hamoid](https://discourse.processing.org/u/hamoid)
#### Post date: [September 14, 2021, 6:13am UTC](https://discourse.processing.org/t/updating-p3-library-for-p4/32191/7 "2021-09-14T06:13:17Z")

</div>

Oh interesting. I haven’t tried to compare the performance in both versions. If you don’t mind sharing, which library is it? Can one see the source code?

BTW I used Gradle instead of Maven: [Gradle | Gradle vs Maven Comparison](https://gradle.org/maven-vs-gradle/) And I used the Kotlin DSL instead of the Groovy DSL because it is typed and has better autocomplete in the IDE and you can ctrl+click on the code to explore the implementation.

---

<div class="post-metadata">

### Author: ![robertesler](https://avatars.discourse-cdn.com/v4/letter/r/ec9cab/32.png) [@robertesler](https://discourse.processing.org/u/robertesler)
#### Post date: [September 14, 2021, 5:56pm UTC](https://discourse.processing.org/t/updating-p3-library-for-p4/32191/8 "2021-09-14T17:56:29Z")

</div>

@hamoid The library is here: [robertesler/Pd4P3". (github.com)](https://github.com/robertesler/Pd4P3) and is open source. And yes, Gradle of course. I think I said Maven and meant Gradle. 🤦‍♂️

---

<div class="post-metadata">

### Author: ![hamoid](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/hamoid/32/58_2.png) [@hamoid](https://discourse.processing.org/u/hamoid)
#### Post date: [September 14, 2021, 10:38pm UTC](https://discourse.processing.org/t/updating-p3-library-for-p4/32191/9 "2021-09-14T22:38:33Z")

</div>

Nice!

It says “for Processing 3” but I looked quickly and didn’t notice Processing dependencies. Would the library work on any JVM project?

---

<div class="post-metadata">

### Author: ![robertesler](https://avatars.discourse-cdn.com/v4/letter/r/ec9cab/32.png) [@robertesler](https://discourse.processing.org/u/robertesler)
#### Post date: [September 14, 2021, 10:43pm UTC](https://discourse.processing.org/t/updating-p3-library-for-p4/32191/10 "2021-09-14T22:43:51Z")

</div>

Yes, it should. Just the examples are made for P3.

---

<div class="post-metadata">

### Author: ![hamoid](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/hamoid/32/58_2.png) [@hamoid](https://discourse.processing.org/u/hamoid)
#### Post date: [September 15, 2021, 5:01pm UTC](https://discourse.processing.org/t/updating-p3-library-for-p4/32191/11 "2021-09-15T17:01:21Z")

</div>

> **[How much faster is Java 17?](https://www.optaplanner.org/blog/2021/09/15/HowMuchFasterIsJava17.html)**
>
> Java 17 (released yesterday) comes with many new features and enhancements. However, most of those require code changes to benefit from. Except for performance. Simply switch your JDK ...
