java exec 参数构造,如何使用JavaExec任务将Java代码嵌入Gradle构建

本文介绍了如何在不创建独立插件的情况下,在Gradle驱动的项目中定义一个特定的Java任务。通过将Java代码放在`src/main/java`目录下,并应用`java`插件,可以将该任务添加到项目的`build.gradle`文件中。任务使用`JavaExec`类型,设置类路径和主类,并可传递参数。这样,即使代码依赖外部库,也可以在每次构建时编译并运行。
摘要由CSDN通过智能技术生成

I have a Gradle-driven project to which I want to add a simple Java task. This task is very specific to the project and if it can be helped I don't want to develop it as a separate plugin. So the question is can I define such custom task within the same build.gradle I'm using for my project? Or is it inevitable that I need to package it as a separate project (plugin) and install to the local repo?

Also it's probably important to note that the original project is not Java related (no other Java code needs to be build)

P.S. Based on comments below:

I would like to add src/main/java/SomeUsefulStuff.java to the existing project and have that file compiled and used as a custom task. I do understand that it needs to be compiled each time I run the build but again - the code will be small. However it will have some external dependencies such as Commons IO

解决方案

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值