title: Basic Dagger example NoClassDefFoundError: dagger/internal/Preconditions
body: <p>I have a very bare bones basic project that is giving me a NoClassDefFoundError.</p>
  
  <p>Here is my gradle: </p>
  
  <pre><code>    plugins {
      id "net.ltgt.apt" version "0.10"
  }
  
  group 'test'
  version '1.0-SNAPSHOT'
  
  apply plugin: 'java'
  
  sourceCompatibility = 1.8
  
  repositories {
      mavenCentral()
  }
  
  dependencies {
      apt group: 'com.google.dagger', name: 'dagger-compiler', version: '2.14.1'
      compile group: 'com.google.dagger', name: 'dagger', version: '2.14.1'
  }
  
  jar {
      manifest {
          attributes 'Implementation-Title': 'test',
                  'Implementation-Version': '1.0.0',
                  'Main-Class': 'test.Main'
      }
      archiveName 'Test.jar'
  }
  </code></pre>
  
  <p>And my Main class: </p>
  
  <pre><code>package test;
  
  import dagger.Component;
  
  public class Main {
  
      @Component(modules = { ServiceModule.class })
      interface Runner {
          ApplicationRunner runner();
      }
  
      public static void main(String[] args) {
          Runner runner = DaggerMain_Runner.builder()
                  .serviceModule(new ServiceModule())
                  .build();
          runner.runner().execute();
      }
  }
  </code></pre>
  
  <p>And My ServiceModule:</p>
  
  <pre><code>package test;
  
  import dagger.Module;
  import dagger.Provides;
  
  @Module
  public class ServiceModule {
      @Provides
      public HelloService provideHelloService() {
          return new HelloServiceImpl();
      }
  }
  </code></pre>
  
  <p>And HelloService: </p>
  
  <pre><code>package test;
  
  public interface HelloService {
      void sayHello();
  }
  </code></pre>
  
  <p>And HelloServiceImpl:</p>
  
  <pre><code>package test;
  
  public class HelloServiceImpl implements HelloService {
      @Override
      public void sayHello() {
          System.err.println("HELLO");
      }
  }
  </code></pre>
  
  <p>And finally ApplicationRunner:</p>
  
  <pre><code>package test;
  
  import javax.inject.Inject;
  
  public class ApplicationRunner {
      public final HelloService helloService;
  
      @Inject
      public ApplicationRunner(HelloService helloService) {
          this.helloService = helloService;
      }
  
      public void execute() {
          helloService.sayHello();
      }
  }
  </code></pre>
  
  <p>if I now run: </p>
  
  <pre><code>./gradlew clean build &amp;&amp; java -jar build/libs/Test.jar
  </code></pre>
  
  <p>I get the following output:</p>
  
  <blockquote>
    <p>:clean :compileJava :processResources NO-SOURCE :classes :jar
    :assemble :compileTestJava NO-SOURCE :processTestResources NO-SOURCE
    :testClasses UP-TO-DATE :test NO-SOURCE :check UP-TO-DATE :build</p>
    
    <p>BUILD SUCCESSFUL</p>
    
    <p>Total time: 1.352 secs Exception in thread "main"
    java.lang.NoClassDefFoundError: dagger/internal/Preconditions     at
    test.DaggerMain_Runner$Builder.serviceModule(DaggerMain_Runner.java:49)
      at test.Main.main(Main.java:14) Caused by:
    java.lang.ClassNotFoundException: dagger.internal.Preconditions   at
    java.net.URLClassLoader.findClass(URLClassLoader.java:381)    at
    java.lang.ClassLoader.loadClass(ClassLoader.java:424)     at
    sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335)     at
    java.lang.ClassLoader.loadClass(ClassLoader.java:357)     ... 2 more</p>
  </blockquote>
  
  <p>Can anyone identify why I'm getting a NoClassDefFoundError? For reference, line 14 of Main is the line that says:</p>
  
  <pre><code>.serviceModule(new ServiceModule())
  </code></pre>
  
  <p>I have tried changing things around quite a lot, using statics, injecting as a property etc. It seems though that I'm not understanding something fundamental here. The only way I could get this to work seemingly was to declare ServiceModule as abstract and use the @Bind annotation style. That's all very well, but what about when I actually want to use @Provides? I don't see why I can't use it in this way.</p>