title: How to resolve the dependency and compile the Junit test classes using Gradle Bulid Tool
body: <p>I'm new to Gradle, currently i added a small java projects and executed well.</p>
  
  <p>Correct me if my understanding since java is available we are able to complie the java project and executed well.</p>
  
  <p>To test i have wirtten a test class with help of junit, but I couldn't not compile and not able to pull the dependency from the maven there was an issue.</p>
  
  <p>When I checked with stacktrace option I find that the issue is <strong>java.net.UnknownHostException: repo1.maven.org</strong> when i tried to access through google it says the Directory browsing is disabled, perhaps it may only for pulling dependency.</p>
  
  <p>Below I have given the steps followed along with the error details.</p>
  
  <p>Kindly help me how to resolve or please suggest how to proceed or correct me if my understanding is wrong.</p>
  
  <p><strong>Compilation of Java Class</strong></p>
  
  <p><img src="https://i.stack.imgur.com/9aHe2.png" alt="enter image description here"></p>
  
  <p><strong>Compilation of Junit without stacktrace</strong></p>
  
  <p><img src="https://i.stack.imgur.com/O7GZX.png" alt="enter image description here"></p>
  
  <p><strong>Compilation of Junit with Stack Trace</strong></p>
  
  <pre><code>D:\Public\NetbeansApp\ShopCart&gt;gradle -s build
  :compileJava
  :processResources UP-TO-DATE
  :classes
  :jar UP-TO-DATE
  :assemble UP-TO-DATE
  :compileTestJava
  
  FAILURE: Build failed with an exception.
  
  * What went wrong:
  Could not resolve all dependencies for configuration ':testCompile'.
  &gt; Could not resolve junit:junit:4.12.
    Required by:
        :ShopCart:unspecified
     &gt; Could not GET 'https://repo1.maven.org/maven2/junit/junit/4.12/junit-4.12.pom'.
        &gt; repo1.maven.org
  
  * Try:
  Run with --info or --debug option to get more log output.
  
  * Exception is:
  org.gradle.api.artifacts.ResolveException: Could not resolve all dependencies for configuration ':testCompile'.
          at org.gradle.api.internal.artifacts.ivyservice.DefaultLenientConfiguration.rethrowFailure(DefaultLenientConfiguration.java:52)
          at org.gradle.api.internal.artifacts.ivyservice.DefaultResolvedConfiguration.rethrowFailure(DefaultResolvedConfiguration.java:36)
          at org.gradle.api.internal.artifacts.ivyservice.SelfResolvingDependencyResolver$FilesAggregatingResolvedConfiguration.rethrowFailure(SelfResol
  vingDependencyResolver.java:110)
          at org.gradle.api.internal.artifacts.ivyservice.ErrorHandlingArtifactDependencyResolver$ErrorHandlingResolvedConfiguration.rethrowFailure(Erro
  rHandlingArtifactDependencyResolver.java:180)
          at org.gradle.api.internal.artifacts.configurations.DefaultConfiguration$ConfigurationFileCollection.getFiles(DefaultConfiguration.java:444)
          at org.gradle.api.internal.artifacts.configurations.DefaultConfiguration.getFiles(DefaultConfiguration.java:205)
          at org.gradle.api.internal.artifacts.configurations.DefaultConfiguration_Decorated.getFiles(Unknown Source)
          at org.gradle.api.internal.file.collections.DefaultFileCollectionResolveContext$FileTreeConverter.convertInto(DefaultFileCollectionResolveCont
  ext.java:191)
          at org.gradle.api.internal.file.collections.DefaultFileCollectionResolveContext.doResolve(DefaultFileCollectionResolveContext.java:103)
          at org.gradle.api.internal.file.collections.DefaultFileCollectionResolveContext.resolveAsFileTrees(DefaultFileCollectionResolveContext.java:75
  )
          at org.gradle.api.internal.file.collections.DefaultFileCollectionResolveContext$FileTreeConverter.convertInto(DefaultFileCollectionResolveCont
  ext.java:182)
          at org.gradle.api.internal.file.collections.DefaultFileCollectionResolveContext.doResolve(DefaultFileCollectionResolveContext.java:98)
          at org.gradle.api.internal.file.collections.DefaultFileCollectionResolveContext.resolveAsFileTrees(DefaultFileCollectionResolveContext.java:75
  )
          at org.gradle.api.internal.file.collections.DefaultFileCollectionResolveContext$FileTreeConverter.convertInto(DefaultFileCollectionResolveCont
  ext.java:182)
          at org.gradle.api.internal.file.collections.DefaultFileCollectionResolveContext.doResolve(DefaultFileCollectionResolveContext.java:98)
          at org.gradle.api.internal.file.collections.DefaultFileCollectionResolveContext.resolveAsFileTrees(DefaultFileCollectionResolveContext.java:75
  )
          at org.gradle.api.internal.file.CompositeFileCollection$1.resolve(CompositeFileCollection.java:88)
          at org.gradle.api.internal.file.CompositeFileCollection.getSourceCollections(CompositeFileCollection.java:143)
          at org.gradle.api.internal.file.CompositeFileTree.getSourceCollections(CompositeFileTree.java:30)
          at org.gradle.api.internal.file.CompositeFileCollection.getFiles(CompositeFileCollection.java:38)
          at org.gradle.api.internal.changedetection.state.DefaultFileCollectionSnapshotter.snapshot(DefaultFileCollectionSnapshotter.java:47)
          at org.gradle.api.internal.changedetection.rules.TaskUpToDateState.&lt;init&gt;(TaskUpToDateState.java:55)
          at org.gradle.api.internal.changedetection.changes.DefaultTaskArtifactStateRepository$TaskArtifactStateImpl.getStates(DefaultTaskArtifactState
  Repository.java:126)
          at org.gradle.api.internal.changedetection.changes.DefaultTaskArtifactStateRepository$TaskArtifactStateImpl.isUpToDate(DefaultTaskArtifactStat
  eRepository.java:69)
          at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.java:52)
          at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:58)
          at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:42)
          at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:52)
          at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:53)
          at org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter.execute(ExecuteAtMostOnceTaskExecuter.java:43)
          at org.gradle.api.internal.AbstractTask.executeWithoutThrowingTaskFailure(AbstractTask.java:305)
          at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.executeTask(AbstractTaskPlanExecutor.java:79)
          at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.processTask(AbstractTaskPlanExecutor.java:63)
          at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.run(AbstractTaskPlanExecutor.java:51)
          at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor.process(DefaultTaskPlanExecutor.java:23)
          at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter.execute(DefaultTaskGraphExecuter.java:88)
          at org.gradle.execution.SelectedTaskExecutionAction.execute(SelectedTaskExecutionAction.java:29)
          at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:62)
          at org.gradle.execution.DefaultBuildExecuter.access$200(DefaultBuildExecuter.java:23)
          at org.gradle.execution.DefaultBuildExecuter$2.proceed(DefaultBuildExecuter.java:68)
          at org.gradle.execution.DryRunBuildExecutionAction.execute(DryRunBuildExecutionAction.java:32)
          at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:62)
          at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:55)
          at org.gradle.initialization.DefaultGradleLauncher.doBuildStages(DefaultGradleLauncher.java:149)
          at org.gradle.initialization.DefaultGradleLauncher.doBuild(DefaultGradleLauncher.java:106)
          at org.gradle.initialization.DefaultGradleLauncher.run(DefaultGradleLauncher.java:86)
          at org.gradle.launcher.exec.InProcessBuildActionExecuter$DefaultBuildController.run(InProcessBuildActionExecuter.java:80)
          at org.gradle.launcher.cli.ExecuteBuildAction.run(ExecuteBuildAction.java:33)
          at org.gradle.launcher.cli.ExecuteBuildAction.run(ExecuteBuildAction.java:24)
          at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:36)
          at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:26)
          at org.gradle.launcher.cli.RunBuildAction.run(RunBuildAction.java:51)
          at org.gradle.internal.Actions$RunnableActionAdapter.execute(Actions.java:171)
          at org.gradle.launcher.cli.CommandLineActionFactory$ParseAndBuildAction.execute(CommandLineActionFactory.java:237)
          at org.gradle.launcher.cli.CommandLineActionFactory$ParseAndBuildAction.execute(CommandLineActionFactory.java:210)
          at org.gradle.launcher.cli.JavaRuntimeValidationAction.execute(JavaRuntimeValidationAction.java:35)
          at org.gradle.launcher.cli.JavaRuntimeValidationAction.execute(JavaRuntimeValidationAction.java:24)
          at org.gradle.launcher.cli.CommandLineActionFactory$WithLogging.execute(CommandLineActionFactory.java:206)
          at org.gradle.launcher.cli.CommandLineActionFactory$WithLogging.execute(CommandLineActionFactory.java:169)
          at org.gradle.launcher.cli.ExceptionReportingAction.execute(ExceptionReportingAction.java:33)
          at org.gradle.launcher.cli.ExceptionReportingAction.execute(ExceptionReportingAction.java:22)
          at org.gradle.launcher.Main.doAction(Main.java:33)
          at org.gradle.launcher.bootstrap.EntryPoint.run(EntryPoint.java:45)
          at org.gradle.launcher.bootstrap.ProcessBootstrap.runNoExit(ProcessBootstrap.java:54)
          at org.gradle.launcher.bootstrap.ProcessBootstrap.run(ProcessBootstrap.java:35)
          at org.gradle.launcher.GradleMain.main(GradleMain.java:23)
  Caused by: org.gradle.internal.resolve.ModuleVersionResolveException: Could not resolve junit:junit:4.12.
  Required by:
      :ShopCart:unspecified
          at org.gradle.api.internal.artifacts.ivyservice.ivyresolve.RepositoryChainDependencyResolver.resolve(RepositoryChainDependencyResolver.java:81
  )
          at org.gradle.api.internal.artifacts.ivyservice.ivyresolve.RepositoryChainAdapter.resolve(RepositoryChainAdapter.java:69)
          at org.gradle.api.internal.artifacts.ivyservice.clientmodule.ClientModuleResolver.resolve(ClientModuleResolver.java:44)
          at org.gradle.api.internal.artifacts.ivyservice.resolveengine.graph.DependencyGraphBuilder$ModuleVersionResolveState.resolve(DependencyGraphBu
  ilder.java:577)
          at org.gradle.api.internal.artifacts.ivyservice.resolveengine.graph.DependencyGraphBuilder$ModuleVersionResolveState.getMetaData(DependencyGra
  phBuilder.java:587)
          at org.gradle.api.internal.artifacts.ivyservice.resolveengine.graph.DependencyGraphBuilder$DependencyEdge.calculateTargetConfigurations(Depend
  encyGraphBuilder.java:272)
          at org.gradle.api.internal.artifacts.ivyservice.resolveengine.graph.DependencyGraphBuilder$DependencyEdge.attachToTargetConfigurations(Depende
  ncyGraphBuilder.java:246)
          at org.gradle.api.internal.artifacts.ivyservice.resolveengine.graph.DependencyGraphBuilder.traverseGraph(DependencyGraphBuilder.java:156)
          at org.gradle.api.internal.artifacts.ivyservice.resolveengine.graph.DependencyGraphBuilder.resolveDependencyGraph(DependencyGraphBuilder.java:
  94)
          at org.gradle.api.internal.artifacts.ivyservice.resolveengine.graph.DependencyGraphBuilder.resolve(DependencyGraphBuilder.java:84)
          at org.gradle.api.internal.artifacts.ivyservice.resolveengine.DefaultDependencyResolver$1.execute(DefaultDependencyResolver.java:122)
          at org.gradle.api.internal.artifacts.ivyservice.resolveengine.DefaultDependencyResolver$1.execute(DefaultDependencyResolver.java:88)
          at org.gradle.internal.Transformers$4.transform(Transformers.java:136)
          at org.gradle.api.internal.artifacts.ivyservice.DefaultIvyContextManager.withIvy(DefaultIvyContextManager.java:61)
          at org.gradle.api.internal.artifacts.ivyservice.DefaultIvyContextManager.withIvy(DefaultIvyContextManager.java:39)
          at org.gradle.api.internal.artifacts.ivyservice.resolveengine.DefaultDependencyResolver.resolve(DefaultDependencyResolver.java:88)
          at org.gradle.api.internal.artifacts.ivyservice.CacheLockingArtifactDependencyResolver$1.run(CacheLockingArtifactDependencyResolver.java:42)
          at org.gradle.internal.Factories$1.create(Factories.java:22)
          at org.gradle.cache.internal.DefaultCacheAccess.useCache(DefaultCacheAccess.java:187)
          at org.gradle.cache.internal.DefaultCacheAccess.useCache(DefaultCacheAccess.java:175)
          at org.gradle.cache.internal.DefaultPersistentDirectoryStore.useCache(DefaultPersistentDirectoryStore.java:106)
          at org.gradle.cache.internal.DefaultCacheFactory$ReferenceTrackingCache.useCache(DefaultCacheFactory.java:187)
          at org.gradle.api.internal.artifacts.ivyservice.DefaultCacheLockingManager.useCache(DefaultCacheLockingManager.java:64)
          at org.gradle.api.internal.artifacts.ivyservice.CacheLockingArtifactDependencyResolver.resolve(CacheLockingArtifactDependencyResolver.java:40)
  
          at org.gradle.api.internal.artifacts.ivyservice.SelfResolvingDependencyResolver.resolve(SelfResolvingDependencyResolver.java:45)
          at org.gradle.api.internal.artifacts.ivyservice.ShortcircuitEmptyConfigsArtifactDependencyResolver.resolve(ShortcircuitEmptyConfigsArtifactDep
  endencyResolver.java:55)
          at org.gradle.api.internal.artifacts.ivyservice.ErrorHandlingArtifactDependencyResolver.resolve(ErrorHandlingArtifactDependencyResolver.java:4
  7)
          at org.gradle.api.internal.artifacts.ivyservice.DefaultConfigurationResolver.resolve(DefaultConfigurationResolver.java:46)
          at org.gradle.api.internal.artifacts.configurations.DefaultConfiguration.resolveNow(DefaultConfiguration.java:250)
          at org.gradle.api.internal.artifacts.configurations.DefaultConfiguration.getResolvedConfiguration(DefaultConfiguration.java:240)
          at org.gradle.api.internal.artifacts.configurations.DefaultConfiguration_Decorated.getResolvedConfiguration(Unknown Source)
          at org.gradle.api.internal.artifacts.configurations.DefaultConfiguration$ConfigurationFileCollection.getFiles(DefaultConfiguration.java:442)
          ... 61 more
  Caused by: org.gradle.internal.resource.transport.http.HttpRequestException: Could not GET 'https://repo1.maven.org/maven2/junit/junit/4.12/junit-4.12
  .pom'.
          at org.gradle.internal.resource.transport.http.HttpClientHelper.performRequest(HttpClientHelper.java:80)
          at org.gradle.internal.resource.transport.http.HttpClientHelper.performRawGet(HttpClientHelper.java:66)
          at org.gradle.internal.resource.transport.http.HttpClientHelper.performGet(HttpClientHelper.java:70)
          at org.gradle.internal.resource.transport.http.HttpResourceAccessor.getResource(HttpResourceAccessor.java:53)
          at org.gradle.internal.resource.transport.http.HttpResourceAccessor.getResource(HttpResourceAccessor.java:36)
          at org.gradle.internal.resource.transfer.ProgressLoggingExternalResourceAccessor.getResource(ProgressLoggingExternalResourceAccessor.java:39)
          at org.gradle.internal.resource.transfer.DefaultCacheAwareExternalResourceAccessor.getResource(DefaultCacheAwareExternalResourceAccessor.java:
  72)
          at org.gradle.api.internal.artifacts.repositories.resolver.DefaultExternalResourceArtifactResolver.downloadStaticResource(DefaultExternalResou
  rceArtifactResolver.java:91)
          at org.gradle.api.internal.artifacts.repositories.resolver.DefaultExternalResourceArtifactResolver.resolveMetaDataArtifact(DefaultExternalReso
  urceArtifactResolver.java:57)
          at org.gradle.api.internal.artifacts.repositories.resolver.ExternalResourceResolver.parseMetaDataFromArtifact(ExternalResourceResolver.java:16
  2)
          at org.gradle.api.internal.artifacts.repositories.resolver.ExternalResourceResolver.resolveStaticDependency(ExternalResourceResolver.java:141)
  
          at org.gradle.api.internal.artifacts.repositories.resolver.MavenResolver.doResolveComponentMetaData(MavenResolver.java:82)
          at org.gradle.api.internal.artifacts.repositories.resolver.ExternalResourceResolver$RemoteRepositoryAccess.resolveComponentMetaData(ExternalRe
  sourceResolver.java:391)
          at org.gradle.api.internal.artifacts.ivyservice.ivyresolve.CacheLockReleasingModuleComponentsRepository$LockReleasingRepositoryAccess$2.run(Ca
  cheLockReleasingModuleComponentsRepository.java:65)
          at org.gradle.internal.Factories$1.create(Factories.java:22)
          at org.gradle.cache.internal.DefaultCacheAccess.longRunningOperation(DefaultCacheAccess.java:237)
          at org.gradle.cache.internal.DefaultCacheAccess.longRunningOperation(DefaultCacheAccess.java:308)
          at org.gradle.cache.internal.DefaultPersistentDirectoryStore.longRunningOperation(DefaultPersistentDirectoryStore.java:114)
          at org.gradle.cache.internal.DefaultCacheFactory$ReferenceTrackingCache.longRunningOperation(DefaultCacheFactory.java:179)
          at org.gradle.api.internal.artifacts.ivyservice.DefaultCacheLockingManager.longRunningOperation(DefaultCacheLockingManager.java:56)
          at org.gradle.api.internal.artifacts.ivyservice.ivyresolve.CacheLockReleasingModuleComponentsRepository$LockReleasingRepositoryAccess.resolveC
  omponentMetaData(CacheLockReleasingModuleComponentsRepository.java:63)
          at org.gradle.api.internal.artifacts.ivyservice.ivyresolve.CachingModuleComponentRepository$ResolveAndCacheRepositoryAccess.resolveComponentMe
  taData(CachingModuleComponentRepository.java:284)
          at org.gradle.api.internal.artifacts.ivyservice.ivyresolve.BaseModuleComponentRepositoryAccess.resolveComponentMetaData(BaseModuleComponentRep
  ositoryAccess.java:38)
          at org.gradle.api.internal.artifacts.ivyservice.ivyresolve.memcache.InMemoryCachedModuleComponentRepository$CachedAccess.resolveComponentMetaD
  ata(InMemoryCachedModuleComponentRepository.java:70)
          at org.gradle.api.internal.artifacts.ivyservice.ivyresolve.ComponentMetaDataResolveState.process(ComponentMetaDataResolveState.java:70)
          at org.gradle.api.internal.artifacts.ivyservice.ivyresolve.ComponentMetaDataResolveState.resolve(ComponentMetaDataResolveState.java:62)
          at org.gradle.api.internal.artifacts.ivyservice.ivyresolve.RepositoryChainDependencyResolver.findBestMatch(RepositoryChainDependencyResolver.j
  ava:114)
          at org.gradle.api.internal.artifacts.ivyservice.ivyresolve.RepositoryChainDependencyResolver.findBestMatch(RepositoryChainDependencyResolver.j
  ava:97)
          at org.gradle.api.internal.artifacts.ivyservice.ivyresolve.RepositoryChainDependencyResolver.resolve(RepositoryChainDependencyResolver.java:70
  )
          ... 92 more
  Caused by: java.net.UnknownHostException: repo1.maven.org
          at org.apache.http.impl.conn.SystemDefaultDnsResolver.resolve(SystemDefaultDnsResolver.java:45)
          at org.apache.http.impl.conn.DefaultClientConnectionOperator.resolveHostname(DefaultClientConnectionOperator.java:278)
          at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:162)
          at org.apache.http.impl.conn.ManagedClientConnectionImpl.open(ManagedClientConnectionImpl.java:294)
          at org.apache.http.impl.client.DefaultRequestDirector.tryConnect(DefaultRequestDirector.java:640)
          at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:479)
          at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:906)
          at org.apache.http.impl.client.DecompressingHttpClient.execute(DecompressingHttpClient.java:137)
          at org.apache.http.impl.client.DecompressingHttpClient.execute(DecompressingHttpClient.java:118)
          at org.gradle.internal.resource.transport.http.HttpClientHelper.performHttpRequest(HttpClientHelper.java:111)
          at org.gradle.internal.resource.transport.http.HttpClientHelper.executeGetOrHead(HttpClientHelper.java:87)
          at org.gradle.internal.resource.transport.http.HttpClientHelper.performRequest(HttpClientHelper.java:78)
          ... 120 more
  
  
  BUILD FAILED
  
  Total time: 14.846 secs
  
  D:\Public\NetbeansApp\ShopCart&gt;
  </code></pre>
  
  <p><strong>App project structure with Test Class</strong></p>
  
  <p><img src="https://i.stack.imgur.com/eFf1K.png" alt="enter image description here"></p>
  
  <p><strong>Build script</strong></p>
  
  <pre><code>apply plugin: 'java'
  
  sourceCompatibility = '1.7'
  [compileJava, compileTestJava]*.options*.encoding = 'UTF-8'
  
  // NetBeans will automatically add "run" and "debug" tasks relying on the
  // "mainClass" property. You may however define the property prior executing
  // tasks by passing a "-PmainClass=&lt;QUALIFIED_CLASS_NAME&gt;" argument.
  //
  // Note however, that you may define your own "run" and "debug" task if you
  // prefer. In this case NetBeans will not add these tasks but you may rely on
  // your own implementation.
  if (!hasProperty('mainClass')) {
      ext.mainClass = ''
  }
  
  jar {
      manifest {
          attributes 'Main-Class': 'com.gradle.shopcart.ShopCartApp'
      }
  }
  
  repositories {
      mavenCentral()
      // You may define additional repositories, or even remove "mavenCentral()".
      // Read more about repositories here:
      //   http://www.gradle.org/docs/current/userguide/dependency_management.html#sec:repositories
  }
  
  dependencies {
      // TODO: Add dependencies here ...
      // You can read more about how to add dependency here:
      //   http://www.gradle.org/docs/current/userguide/dependency_management.html#sec:how_to_declare_your_dependencies
      testCompile group: 'junit', name: 'junit', version: '4.12'
  
  }
  </code></pre>
  
  <p><strong>Error of Directory</strong></p>
  
  <p><img src="https://i.stack.imgur.com/xBGz3.png" alt="enter image description here"></p>