英文:
Shell script to run gradle project
问题
我是一个完全的初学者,对编写Shell脚本以及使用gradle也不熟悉。
我有一个gradle项目,其输出是一些图片。我通过命令行参数传递两个路径,表示一个包含.java源文件的目录和一个输出文件名:
gradle run --args='C:/user/.../src/ result'
我的项目解析这些源文件并为每个文件生成类图,然后输出一个图像,显示所有源文件的UML类图。
我的“客户端”希望从命令行中得到以下内容:
commandName <.java源文件> <输出文件名>
其中“.java源文件”是包含.java文件的源代码目录,而“输出文件名”是包含类图的图像的名称。
我想创建一个Shell脚本,或者采取某种方法创建一个像上面一样的简洁命令,还要确保该脚本可以使用给定的参数运行gradle项目。
我还希望确保任何人都可以下载我的gradle项目,并能够以最小的设置运行此命令。在这种情况下,我是否最好使用Makefile?
编辑:
Shell脚本比我想象的要简单。这是我目前拥有的全部内容:
gradle run --args="$*"
我读到可以使用别名来使用“简单”的名称执行它。如果其他人下载了我的项目,他们如何能够以简单的名称运行此脚本,而无需自己设置别名呢?
英文:
I'm a complete beginner with writing shell scripts, and with using gradle for that matter.
I have a gradle project whose output is some images. I pass two paths as command line arguments that represents a directory of .java sources, and an output file name:
gradle run --args='C:/user/.../src/ result'
My project parses the sources and generates class diagrams of each file, then outputs an image showing all of the UML class diagrams for each source file.
My "client" expects the following from the command line:
commandName <.java source> <output file name>
Where the ".java sources" is the source directory containing .java files, and the "output file name" is the name of the image containing class diagrams.
I would like to create a shell script, or enact some method to create a neat command like above, and also make sure that this script can run the gradle project with given arguments.
I would also like to ensure that anyone can download my gradle project, and be able to run this command with minimal setup. Would I be better off using a makefile here?
Edit:
The shell script is more minimal than I thought. Here is all I have so far:
gradle run --args="$*"
I've read that I can use an alias to execute this with a "simple" name. If someone else downloads my project, how can they run this script with the simple name without setting the alias themselves?
专注分享java语言的经验与见解,让所有开发者获益!
评论