Debugging Tips for Cordapps

When writing CorDapps, our developers sometimes run into compilation issues, and the reason isn’t always apparent. For example, if you’re finding a java.lang.ClassNotFoundException or an import that fails to work even though the class name is right, there are a couple of things you can do to get your project to build correctly. Here are the steps that solve this issue most often.

  • First, always make sure your machine is configured correctly.
  • Next, make sure to look at your Gradle files. You may be missing a critical jar or dependency. I recommend developers to compare their build.Gradle files (and submodule build.Gradle files!) to the cordapp template in either java or kotlin.
  • Third, make sure your Corda nodes are getting the correct modules by default (for example, having cordapp project(’: contracts’) propagate to all nodes is probably a good idea.)
  • Fourth, double check the configuration of CorDapps using the features you’re trying to get to work. Our sample repo has a lot of different options. For example, if you’re working on a SchedulableState CorDapp, the HeartBeat CorDapp would be an excellent resource for you. (Remember that all of our samples are in both java and kotlin.)
  • Finally, it’s always possible that a Gradle clean and resync can get things back in order.

These kinds of structural issues are generally solved by trying to make sure that you’re following the CorDapp template guidelines.

Some other things you can check if you’re looking for ideas on possible compilation problems:

  • Gradle properties (we call the file
  • Gradle wrapper version number
  • Make sure the class names and paths are correct
  • Ensure your workflows Gradle file has a dependency on your contracts, but not the other way around
  • Make sure your IDE is using the correct version of java (even if the system version is right; IntelliJ, for example, can manage multiple SDKs)

Here are the links again to the templates in both java and kotlin.