bndtools / bnd

Bnd/Bndtools. Tooling to build OSGi bundles including Eclipse, Maven, and Gradle plugins.
https://bndtools.org
Other
532 stars 305 forks source link

Gradle plugin does not honor the instruction "-sources: false" #6230

Closed dmm9 closed 2 months ago

dmm9 commented 3 months ago

My bundle jar, created with the gradle plugin for bnd workspace build had not only one, but two copies of the source code. Adding -sources: false to bnd.bnd only removes one of the copies of the source code.

My assumption is that the gradle plugin takes the src param from bnd.bnd and adds all files to the jar, which is not the standard behavior of gradle. I have created my own workaround by adding build.gradle to the app folder in order to exclude all files, but I think this should be done by the bnd gradle plugin by default...

Example

With the following repo:

├── app
│   ├── bnd.bnd
│   ├── build.gradle
│   └── src
│       ├── backend    # java
│       │   ├── package1
│       │   └── ...
│       └── frontend    # typescript
│           ├── node_modules
│           ├── package.json
│           └── ...
├── cnf
├── gradle.properties
├── gredlew
├── gradlew.bat
└── settings.gradle

and

# bnd.bnd
src: src
-sources: false
...

Without -sources:false, the .jar has:

└── app.jar
    ├── backend     ######## <------- Copy #1 (Java .class files, as expected, but also .xml, README.md, ...)
    ├── frontend    ######## <------- Copy #1 (full copy of frontend)
    │       ├── node_modules
    │       ├── package.json
    │       └── ...
    ├── META-INF
    ├── OSGI-INF
    └── OSGI-OPT
        └── src   ######## <------- Copy #2 (full copy of frontend + backend)
            ├── backend
            └── frontend

And with -sources:false, only the OSGI-OPT/src disappears.

My assumption is that the gradle plugin takes the src param and adds all files to the jar, which is not the standard behavior of gradle. I have created my own workaround by adding build.gradle to the app folder in order to exclude all files, but I think this should be done by the bnd gradle plugin by default...

// app/build.gradle

processResources {
    include '**/*.class'
}
pkriens commented 3 months ago

This is outside our control. We do the OSGI-OPT/src but the other parts depend on your compiler settings. Compilers generally will copy resource in the source directory. Although they generally will not copy java files.

dmm9 commented 3 months ago

I doubt it. According to this post, Gradle only includes compiled classes by default:

grafik

Source here. Also documented in Gradle docs

So I guess the bnd-gradle-plugin is modifying the gradle task to include more than just the compiled classes. Does it make sense?

pkriens commented 3 months ago

That could be right because Eclipse compiler is doing this so to get the same semantics we copy the resources in the source directory. However, this does not include the Java sources?

pkriens commented 2 months ago

Please reopen if you want to pursue this further. As far as I am concerned I think bnd does the right thing