Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optional dependencies #19

Closed
ocroquette opened this issue Oct 14, 2016 · 7 comments
Closed

Optional dependencies #19

ocroquette opened this issue Oct 14, 2016 · 7 comments

Comments

@ocroquette
Copy link

Hi,

I create a bundle from commons-logging:
dependencies { platform 'commons-logging:commons-logging:1.1.1' }

It has an optional dependency to Avalon:
<dependency> <groupId>avalon-framework</groupId> <artifactId>avalon-framework</artifactId> <version>4.1.3</version> <optional>true</optional> </dependency>

It looks like bnd-platform makes a hard dependency at out it:
Import-Package: javax.servlet,org.apache.avalon.framework.logger,org.apa che.log,org.apache.log4j

Is that expected? In other words, do pnd-platform support optional dependencies automatically?
If not, is there a workaround? I tried various things, like using override and importIgnorePackages, but nothing worked unfortunately.

@stempler
Copy link
Owner

Gradle does not support optional dependencies in its dependency management, so that information is lost.

Workaround is easy if you know the bundle where you want to make the dependency optional and the respective package names. You can configure the bundle to use optional package imports, similar to the first example here.

@ocroquette
Copy link
Author

Thanks for the quick reply. I tried that, but it's not working, so I must do something wrong. Here is my script:

buildscript {
  repositories {
      jcenter()
  }
  dependencies {
      classpath 'org.standardout:bnd-platform:1.4.0'
  }
}

repositories {
  mavenCentral()
}

apply plugin: 'org.standardout.bnd-platform'

dependencies {
  platform 'commons-logging:commons-logging:1.1.1'
}

platform {
  bnd(group: 'commons-logging', name: 'commons-logging') {
      optionalImport 'org.apache.avalon.framework.logger'
  }
}

And here is the generated manifest:

Manifest-Version: 1.0
Archiver-Version: Plexus Archiver
Build-Jdk: 1.4.2_16
Built-By: dlg01
Bundle-ManifestVersion: 2
Bundle-Name: commons-logging.commons-logging
Bundle-SymbolicName: commons-logging
Bundle-Version: 1.1.1.bnd-u8sQ6Q
Export-Package: org.apache.commons.logging;version="1.1.1",org.apache.co
 mmons.logging.impl;version="1.1.1";uses:="javax.servlet,org.apache.aval
 on.framework.logger,org.apache.commons.logging,org.apache.log,org.apach
 e.log4j"
Extension-Name: org.apache.commons.logging
Implementation-Title: Jakarta Commons Logging
Implementation-Vendor: Apache Software Foundation
Implementation-Vendor-Id: org.apache
Implementation-Version: 1.1.1
Import-Package: javax.servlet,org.apache.avalon.framework.logger,org.apache.log,org.apache.log4j
Originally-Created-By: Apache Maven
Specification-Title: Jakarta Commons Logging
Specification-Vendor: Apache Software Foundation
Specification-Version: 1.0
X-Compile-Source-JDK: 1.2
X-Compile-Target-JDK: 1.2

@stempler
Copy link
Owner

Strange, the configuration looks alright. Does it make a difference if you use org.apache.avalon.framework.logger.* or org.apache.avalon.framework.* for the optional import instruction?

@ocroquette
Copy link
Author

Hmmm, no, it doesn't.

I also tried this as a cross check:

      optionalImport 'javax.servlet'

It doesn't have any effect either.

@stempler
Copy link
Owner

Just copied your build.gradle and let it run locally, this is the Manifest I get:

Manifest-Version: 1.0
Archiver-Version: Plexus Archiver
Build-Jdk: 1.4.2_16
Built-By: dlg01
Bundle-ManifestVersion: 2
Bundle-Name: commons-logging.commons-logging
Bundle-SymbolicName: commons-logging
Bundle-Version: 1.1.1.bnd-5zkmsg
Export-Package: org.apache.commons.logging;version="1.1.1",org.apache.co
 mmons.logging.impl;version="1.1.1";uses:="javax.servlet,org.apache.aval
 on.framework.logger,org.apache.commons.logging,org.apache.log,org.apach
 e.log4j"
Extension-Name: org.apache.commons.logging
Implementation-Title: Jakarta Commons Logging
Implementation-Vendor: Apache Software Foundation
Implementation-Vendor-Id: org.apache
Implementation-Version: 1.1.1
Import-Package: org.apache.avalon.framework.logger;resolution:=optional,
 javax.servlet,org.apache.log,org.apache.log4j
Originally-Created-By: Apache Maven
Specification-Title: Jakarta Commons Logging
Specification-Vendor: Apache Software Foundation
Specification-Version: 1.0
X-Compile-Source-JDK: 1.2
X-Compile-Target-JDK: 1.2

So everything seems to work fine. Maybe an issue with the Gradle version? I just used Gradle 2.4, after that I tried it with Gradle 3.1, with the same result.

@stempler
Copy link
Owner

Strange though that the hash is different than yours - this would hint at a different configuration. Did you maybe look into an old Jar?
Maybe also run the clean task, e.g. gradle clean updateSite

@ocroquette
Copy link
Author

ocroquette commented Oct 14, 2016

I deleted ~/.groovy, ~/.gradle, killed all daemons etc., and now it works as expected, both with Gradle 2.9 that I used in the first place, and 3.1. So I guess something was wrong with my environment. Strangely enough, I had the same symptoms on my Mac and on a Windows PC. I fixed it on my Mac, I will check on Windows on monday.

During the many trials and errors, I also had an error message during the Eclipse download like the one in this bug report:
michel-kraemer/gradle-download-task#47
It's gone now. It was also probably due to environment/caches, maybe it's related to the original issue I had.

Feel free to close the issue. Thanks again for your help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants