Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
303 views
in Technique[技术] by (71.8m points)

Moving from compiling Java with GNU Make to gradle

I have a project generating many (>100) small Java tools.

For years I've used a GNU Makefile (see here) to manage the compilation of my tools (much more compact + simplier than an ant/Maven file). Basically I declared a Makefile macro that creates an executable jar using small set of parameters:

define compile-htsjdk-cmd

$(1)  : ${htsjdk.jars} 
        $(addsuffix .java,$(addprefix ${src.dir}/,$(subst .,/,$(2)))) 
        $(3)
    (...)
    ${JAVAC} 
        -d ${tmp.dir} 
        -g -classpath "$$(subst $$(SPACE),:,$$(filter %.jar,$$^))" 
        -sourcepath ${src.dir}:${generated.dir}/java $$(filter %.java,$$^)
  (...)
  ${JAR} cfm ${dist.dir}/$(1)$(if ${standalone},-fat).jar ${tmp.mft}  -C ${tmp.dir} .
  (...)
endef


$(eval $(call compile-htsjdk-cmd,referencetovcf,${jvarkit.package}.tools.misc.ReferenceToVCF,${jcommander.jar}))
$(eval $(call compile-htsjdk-cmd,sam2json,${jvarkit.package}.tools.misc.SamToJson,${jcommander.jar} ${gson.jar} ))
$(eval $(call compile-htsjdk-cmd,sam2psl,${jvarkit.package}.tools.misc.SamToPsl,${jcommander.jar} ))
$(eval $(call compile-htsjdk-cmd,sam2tsv,${jvarkit.package}.tools.sam2tsv.Sam2Tsv,${jcommander.jar} ))
(...)

The system worked for years without any problem. Now, I'd like to handle more configurations (using more than one jdk, adding special things in some Manifest files ets...) And as far as I understand, gradle would be the best tool to achieve this.

I saw some examples with only one target but it's not clear to me how I could easily transform my Makefile into a gradle file. Can I put all my targets in the same build.gradle file? How can I (and should I?) mimic what I did with my makefile macro?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Ok I managed to build a big build.gradle file containing some dynamic calls to ant.javac : https://github.com/lindenb/jvarkit/blob/8ef260931025c29942a3231ea876b59e5c2dcc46/build.gradle

It works fine so far...


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...