FileNotFoundException when running gradle build using a repo index that was generated in the same gradle execution

195 views
Skip to first unread message

Eli Jordan

unread,
Dec 2, 2015, 7:42:20 AM12/2/15
to bndtools-users
I am using the bnd repo index cli tool to generate an index file for some bundles that are downloaded, and used as dependency in a gradle+bnd build. The generated index file is specified as a FixedIndexedRepo in the bnd plugins configuration. I am trying to complete the automation of the build, so that it downloads the bundles, indexes them, then runs a full build all with one command. However, when I run both the indexing and the build in the same gradle execution 

e.g. ./gradlew generateIndex buildNeeded 

then I get a FileNotFoundException from bnd saying that the index file for the repo does not exist. 

If I run 

./gradlew generateIndex && ./gradlew buildNeeded

that is, perform the steps in different gradle executions everything works fine.

Note: I did try setting bnd_preCompileRefresh=true but this didn't help.

Whats happening here? Is the FixedIndexedRepo initialised before the index file is created, and failing? Why would the refresh not fix this?

Any help greatly appreciated.

BJ Hargrave

unread,
Dec 2, 2015, 7:55:21 AM12/2/15
to bndtool...@googlegroups.com
Eli,

I am not familiar with the generateIndex target as it is not part of the bnd gradle plugin.

When the gradle build starts, the bnd gradle plugin will create a Workspace object which will read the cnf and initialize the workspace plugins including repo plugins. So if your build makes an index which is needed by the workspace repo plugins, you will need to refresh the Workspace to refresh the workspace repo plugins. So your generateIndex target will need to get the bnd Project object for the cnf project and call refresh on it after it makes a new index. Something like: cnf.bnd.project.refresh()

bnd_preCompileRefresh=true only refreshes projects as it compiles them but you only need to refresh the cnf project after you generate new indexes. So bnd_preCompileRefresh=true is not going to help you.

--
You received this message because you are subscribed to the Google Groups "bndtools-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bndtools-user...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
--
BJ

Eli Jordan

unread,
Dec 2, 2015, 5:34:21 PM12/2/15
to bndtool...@googlegroups.com
Thanks BJ, that is very helpful! I will try the suggested changes today.

The generateIndex task is one that I wrote, that launches the repo index cli tool.

Thanks
Eli
You received this message because you are subscribed to a topic in the Google Groups "bndtools-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/bndtools-users/OQ0Ns5v0ELo/unsubscribe.
To unsubscribe from this group and all its topics, send an email to bndtools-user...@googlegroups.com.

Eli Jordan

unread,
Dec 2, 2015, 10:46:29 PM12/2/15
to bndtool...@googlegroups.com
Ok, so I tried this out, but it doesn’t seem to address the issue. Maybe the refresh doesn’t always refresh the repo plugins? I have created a github repo to demonstrate the issue here https://github.com/eli-jordan/bnd_index_issue

The generateIndex task is defined in the root build.gradle file.

If you run, from the root 

gradle generateIndex buildNeeded

the failure will be created

Note: 
   1. You have to remove the cnf/demo-repo/index.xml file to reproduce the issue again after running this once
   2. If you delete the index.xml file and run ‘gradle generateIndex && gradle buildNeeded’ all is well


You received this message because you are subscribed to a topic in the Google Groups "bndtools-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/bndtools-users/OQ0Ns5v0ELo/unsubscribe.
To unsubscribe from this group and all its topics, send an email to bndtools-user...@googlegroups.com.

BJ Hargrave

unread,
Dec 3, 2015, 12:40:30 PM12/3/15
to bndtool...@googlegroups.com
The problem is that the error is still in the workspace from before the refresh. So you need to clear the errors and then refresh. This change works.

[hargrave@macbookpro3 bnd_index_issue (master)]$ git diff
diff --git a/build.gradle b/build.gradle
index f97a5e7..da8ca59 100644
--- a/build.gradle
+++ b/build.gradle
@@ -34,14 +34,14 @@ subprojects {
 }
 
  task generateIndex(type: IndexRepository) {
-       def cnf = rootProject.project(':cnf')
        repositoryName = 'Demo Repo'
        indexFile = file("${cnf.projectDir}/demo-repo/index.xml")
        bundles = fileTree(dir: "${cnf.projectDir}/demo-repo", includes: ['**/*jar'])
        rootUrl = file("${cnf.projectDir}/demo-repo")
- } << {
-       cnf.bnd.project.refresh()
-    // bndWorkspace.refresh() // I tried this too, but it didn't work either
+      doLast {
+        bndWorkspace.clear()
+        bndWorkspace.refresh()
+   }

Eli Jordan

unread,
Dec 3, 2015, 10:34:20 PM12/3/15
to bndtool...@googlegroups.com
Hmm… with this change I still get an error, when it tries to resolve the dependency (See below error). Note that the index.xml file needs to be removed and is successfully created even when the task fails. It’s as if it is not successfully loading the repo plugin.

I even tried 

doLast {
   bndWorkspace.getPlugins(Refreshable).each { it.refresh() }
   bndWorkspace.clear()
   bndWorkspace.forceRefresh()
   bndWorkspace.currentProjects.each { it.propertiesChanged() }
}

and got the same error

:has.a.dependency:classes UP-TO-DATE
:has.a.dependency:jar
Warning: The JAR is empty: The instructions for the JAR named has.a.dependency did not cause any content to be included, this is likely wrong
Error  : Cannot find /error/com.google.inject;version=3.0 Not found in [bnd-cache, Demo Repo]
Error  : com.google.inject;version=3.0 Not found in [bnd-cache, Demo Repo]
:has.a.dependency:jar FAILED

FAILURE: Build failed with an exception.

BJ Hargrave

unread,
Dec 3, 2015, 10:38:53 PM12/3/15
to bndtool...@googlegroups.com
Yes I saw that too but it is another problem (which I assume was related to the example workspace being limited to the current problem.)

But the original problem you raised is addressed. I don't know what this secondary problem is but I don't see that it is related to the gradle plugin.

--
You received this message because you are subscribed to the Google Groups "bndtools-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bndtools-user...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
--
BJ

Eli Jordan

unread,
Dec 3, 2015, 10:47:44 PM12/3/15
to bndtool...@googlegroups.com
But still if I run the tasks in separate gradle executions, the error does not occur (in this sample workspace, and my ‘production’ one). It’s only when the index generation and the build are called together that the error occurs. 

This seems to indicate that the index file is successfully and correctly generated, but refreshing the workspace doesn’t correctly pickup the files contents.

Maybe there is a better way to approach this problem? Basically I am downloading a zip file that contains the runtime my application will run in, and I want to index the api bundles within that runtime to compile against. Is there a better way to do this?

You received this message because you are subscribed to a topic in the Google Groups "bndtools-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/bndtools-users/OQ0Ns5v0ELo/unsubscribe.
To unsubscribe from this group and all its topics, send an email to bndtools-user...@googlegroups.com.

BJ Hargrave

unread,
Dec 10, 2015, 11:52:17 PM12/10/15
to bndtool...@googlegroups.com
It is still the issue of clearing errors that were recorded before the refresh. There are still errors left behind in the projects even though the errors were cleared from the workspace. The following change clears the errors in the projects and allows the build to complete.

[hargrave@macbookpro3 bnd_index_issue (master)]$ git diff
diff --git a/build.gradle b/build.gradle
index f97a5e7..70a8b73 100644
--- a/build.gradle
+++ b/build.gradle
@@ -34,14 +34,17 @@ subprojects {

 }
 
  task generateIndex(type: IndexRepository) {
-       def cnf = rootProject.project(':cnf')
        repositoryName = 'Demo Repo'
        indexFile = file("${cnf.projectDir}/demo-repo/index.xml")
        bundles = fileTree(dir: "${cnf.projectDir}/demo-repo", includes: ['**/*jar'])
        rootUrl = file("${cnf.projectDir}/demo-repo")
- } << {
-       cnf.bnd.project.refresh()
-    // bndWorkspace.refresh() // I tried this too, but it didn't work either
+   doLast {
+      bndWorkspace.clear()
+      rootProject.subprojects {
+        bnd.project.clear()
+      }
+      bndWorkspace.refresh()
+  }
  }




BJ
Reply all
Reply to author
Forward
0 new messages