• 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏吧

生成gradle java应用程序的dockerfile

java 来源:Barış Cirit 12次浏览

这是我的build.gradle文件。在eclipse中,我通过eclipse中的gradle运行docker任务,没有错误,它会生成dockerfile和图像。但是当我尝试在项目位置的ubuntu终端中写入gradle build时,出现错误。我将尝试通过编写gradle distDucker来运行任务以获得项目的dockerfile。生成gradle java应用程序的dockerfile

的build.gradle文件:

buildscript { 
repositories { 
mavenCentral() 
} 
dependencies { 
    classpath "se.transmode.gradle:gradle-docker:1.2" 
} 
} 

apply plugin: 'java' 
apply plugin: 'application' 
apply plugin: 'docker' 
apply plugin: 'eclipse' 

repositories { 
mavenCentral() 
} 

sourceCompatibility = 1.8 

mainClassName = 'kafka.MyProducer' 

applicationDefaultJvmArgs = ['-Xmx1g', 
         '-Xms1g'] 

dependencies { 
compile group: 'org.apache.kafka', name: 'kafka_2.11',version: '0.10.0.0'  
} 

task copyConf(type: Copy) { 
from System.getProperty('user.dir') + "/conf" 
into "$buildDir/conf" 
} 

task createConf { 
def conf = file("$buildDir/conf") 
outputs.dir conf 
doLast { 
    conf.mkdirs() 
    copyConf.execute() 
} 
} 

distributions { 
main { 
    contents { 
     from(createConf) { into "/conf" } 
    } 
} 
} 

docker { 
baseImage = 'brscrt/java-8' 
maintainer = 'Baris Cirit "[email protected]"' 
} 

distDocker { 
tag = 'brscrt/kafkaproducer' 
    version = 'latest' 

push = project.hasProperty('push') ? project.property('push') : false 
} 


task wrapper(type: Wrapper) { gradleVersion = '2.14' } 

此错误在终端:

[email protected]:~/workspace/KafkaProducer_Gr$ gradle build 

FAILURE: Build failed with an exception. 

* Where: 
Build file '/home/baris/workspace/KafkaProducer_Gr/build.gradle' line: 12 

* What went wrong: 
A problem occurred evaluating root project 'KafkaProducer_Gr'. 
    > Could not create task of type 'DockerTask'. 

* Try: 
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. 

BUILD FAILED 

Total time: 4.9 secs 

堆栈跟踪是复杂的。输入后gradle build --stacktrace

[email protected]:~/workspace/KafkaProducer_Gr$ gradle build --stacktrace 

FAILURE: Build failed with an exception. 

* Where: 
Build file '/home/baris/workspace/KafkaProducer_Gr/build.gradle' line: 12 

* What went wrong: 
A problem occurred evaluating root project 'KafkaProducer_Gr'. 
> Could not create task of type 'DockerTask'. 

* Try: 
Run with --info or --debug option to get more log output. 

* Exception is: 
org.gradle.api.GradleScriptException: A problem occurred evaluating root project 'KafkaProducer_Gr'. 
at org.gradle.groovy.scripts.internal.DefaultScriptRunnerFactory$ScriptRunnerImpl.run(DefaultScriptRunnerFactory.java:54) 
at org.gradle.configuration.DefaultScriptPluginFactory$ScriptPluginImpl.apply(DefaultScriptPluginFactory.java:127) 
at org.gradle.configuration.BuildScriptProcessor.evaluate(BuildScriptProcessor.java:38) 
at org.gradle.configuration.LifecycleProjectEvaluator.evaluate(LifecycleProjectEvaluator.java:43) 
at org.gradle.api.internal.project.AbstractProject.evaluate(AbstractProject.java:466) 
at org.gradle.api.internal.project.AbstractProject.evaluate(AbstractProject.java:77) 
at org.gradle.configuration.ProjectEvaluationConfigurer.execute(ProjectEvaluationConfigurer.java:23) 
at org.gradle.configuration.ProjectEvaluationConfigurer.execute(ProjectEvaluationConfigurer.java:21) 
at org.gradle.api.internal.Actions$CompositeAction.execute(Actions.java:78) 
at org.gradle.api.internal.Actions$TransformingActionAdapter.execute(Actions.java:130) 
at org.gradle.api.internal.project.AbstractProject.configure(AbstractProject.java:442) 
at org.gradle.api.internal.project.AbstractProject.allprojects(AbstractProject.java:437) 
at org.gradle.configuration.DefaultBuildConfigurer.configure(DefaultBuildConfigurer.java:40) 
at org.gradle.initialization.DefaultGradleLauncher.doBuildStages(DefaultGradleLauncher.java:142) 
at org.gradle.initialization.DefaultGradleLauncher.doBuild(DefaultGradleLauncher.java:113) 
at org.gradle.initialization.DefaultGradleLauncher.run(DefaultGradleLauncher.java:81) 
at org.gradle.launcher.cli.ExecuteBuildAction.run(ExecuteBuildAction.java:38) 
at org.gradle.launcher.exec.InProcessGradleLauncherActionExecuter.execute(InProcessGradleLauncherActionExecuter.java:39) 
at org.gradle.launcher.exec.InProcessGradleLauncherActionExecuter.execute(InProcessGradleLauncherActionExecuter.java:25) 
at org.gradle.launcher.cli.RunBuildAction.run(RunBuildAction.java:50) 
at org.gradle.api.internal.Actions$RunnableActionAdapter.execute(Actions.java:171) 
at org.gradle.launcher.cli.CommandLineActionFactory$ParseAndBuildAction.execute(CommandLineActionFactory.java:201) 
at org.gradle.launcher.cli.CommandLineActionFactory$ParseAndBuildAction.execute(CommandLineActionFactory.java:174) 
at org.gradle.launcher.cli.CommandLineActionFactory$WithLogging.execute(CommandLineActionFactory.java:170) 
at org.gradle.launcher.cli.CommandLineActionFactory$WithLogging.execute(CommandLineActionFactory.java:139) 
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:48) 
at org.gradle.launcher.bootstrap.EntryPoint.run(EntryPoint.java:45) 
at org.gradle.launcher.Main.main(Main.java:39) 
at org.gradle.launcher.bootstrap.ProcessBootstrap.runNoExit(ProcessBootstrap.java:50) 
at org.gradle.launcher.bootstrap.ProcessBootstrap.run(ProcessBootstrap.java:32) 
at org.gradle.launcher.GradleMain.main(GradleMain.java:26) 
Caused by: org.gradle.api.tasks.TaskInstantiationException: Could not create task of type 'DockerTask'. 
at org.gradle.api.internal.project.taskfactory.TaskFactory$1.call(TaskFactory.java:115) 
at org.gradle.api.internal.project.taskfactory.TaskFactory$1.call(TaskFactory.java:110) 
at org.gradle.api.internal.AbstractTask.injectIntoNewInstance(AbstractTask.java:138) 
at org.gradle.api.internal.project.taskfactory.TaskFactory.createTaskObject(TaskFactory.java:110) 
at org.gradle.api.internal.project.taskfactory.TaskFactory.createTask(TaskFactory.java:70) 
at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory.createTask(AnnotationProcessingTaskFactory.java:93) 
at org.gradle.api.internal.project.taskfactory.DependencyAutoWireTaskFactory.createTask(DependencyAutoWireTaskFactory.java:39) 
at org.gradle.api.internal.tasks.DefaultTaskContainer.add(DefaultTaskContainer.java:53) 
at org.gradle.api.internal.project.AbstractProject.task(AbstractProject.java:929) 
at org.gradle.api.Project$task.call(Unknown Source) 
at se.transmode.gradle.plugins.docker.DockerPlugin.addDistDockerTask(DockerPlugin.groovy:48) 
at se.transmode.gradle.plugins.docker.DockerPlugin.this$2$addDistDockerTask(DockerPlugin.groovy) 
at se.transmode.gradle.plugins.docker.DockerPlugin$_apply_closure1.doCall(DockerPlugin.groovy:42) 
at org.gradle.api.internal.ClosureBackedAction.execute(ClosureBackedAction.java:58) 
at org.gradle.api.internal.Actions$FilteredAction.execute(Actions.java:203) 
at org.gradle.api.internal.DefaultDomainObjectCollection.all(DefaultDomainObjectCollection.java:110) 
at org.gradle.api.internal.DefaultDomainObjectCollection.all(DefaultDomainObjectCollection.java:115) 
at org.gradle.api.DomainObjectCollection$all.call(Unknown Source) 
at se.transmode.gradle.plugins.docker.DockerPlugin.apply(DockerPlugin.groovy:41) 
at se.transmode.gradle.plugins.docker.DockerPlugin.apply(DockerPlugin.groovy) 
at org.gradle.api.internal.plugins.DefaultProjectsPluginContainer.providePlugin(DefaultProjectsPluginContainer.java:107) 
at org.gradle.api.internal.plugins.DefaultProjectsPluginContainer.addPluginInternal(DefaultProjectsPluginContainer.java:71) 
at org.gradle.api.internal.plugins.DefaultProjectsPluginContainer.apply(DefaultProjectsPluginContainer.java:37) 
at org.gradle.api.internal.plugins.DefaultObjectConfigurationAction.applyPlugin(DefaultObjectConfigurationAction.java:101) 
at org.gradle.api.internal.plugins.DefaultObjectConfigurationAction.access$200(DefaultObjectConfigurationAction.java:32) 
at org.gradle.api.internal.plugins.DefaultObjectConfigurationAction$3.run(DefaultObjectConfigurationAction.java:72) 
at org.gradle.api.internal.plugins.DefaultObjectConfigurationAction.execute(DefaultObjectConfigurationAction.java:114) 
at org.gradle.api.internal.project.AbstractProject.apply(AbstractProject.java:854) 
at org.gradle.api.Project$apply.call(Unknown Source) 
at org.gradle.api.internal.project.ProjectScript.apply(ProjectScript.groovy:34) 
at org.gradle.api.Script$apply.callCurrent(Unknown Source) 
at build_6evdo45vm72o57c2gvqaus0hpp.run(/home/baris/workspace/KafkaProducer_Gr/build.gradle:12) 
at org.gradle.groovy.scripts.internal.DefaultScriptRunnerFactory$ScriptRunnerImpl.run(DefaultScriptRunnerFactory.java:52) 
... 32 more 
Caused by: java.lang.NoClassDefFoundError: org/codehaus/groovy/runtime/typehandling/ShortTypeHandling 
at se.transmode.gradle.plugins.docker.DockerTask.<init>(DockerTask.groovy:104) 
at se.transmode.gradle.plugins.docker.DockerTask_Decorated.<init>(Unknown Source) 
at org.gradle.api.internal.DependencyInjectingInstantiator.newInstance(DependencyInjectingInstantiator.java:62) 
at org.gradle.api.internal.ClassGeneratorBackedInstantiator.newInstance(ClassGeneratorBackedInstantiator.java:36) 
at org.gradle.api.internal.project.taskfactory.TaskFactory$1.call(TaskFactory.java:113) 
... 64 more 
Caused by: java.lang.ClassNotFoundException: org.codehaus.groovy.runtime.typehandling.ShortTypeHandling 
... 69 more 


BUILD FAILED 

Total time: 4.897 secs 

线中的build.gradle 12:apply plugin: 'docker'


===========解决方案如下:

看起来你正在使用的gradle产出/常规的旧版本,因为org.codehaus.groovy.runtime.typehandling.ShortTypeHandling在常规2.3引入根据堆栈跟踪,类加载器在尝试应用docker插件时无法找到它。


版权声明:本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系管理员进行删除。
喜欢 (0)