简体   繁体   English

使用TFS构建Java项目

[英]Building java project with TFS

A very small portion of our codebase is some legacy Java code. 我们的代码库中只有一小部分是一些旧版Java代码。 I'm trying to add a new build that would invoke ant to build this project. 我正在尝试添加一个新的构建,该构建将调用ant来构建该项目。

The first problem is that TFS doesn't allow you to create a build that doesn't build a .Net solution. 第一个问题是TFS不允许您创建不构建.Net解决方案的构建。 I got around this by copying a previous build file and adding an EndToEndIteration task which is the entry point for the build. 通过复制先前的构建文件并添加EndToEndIteration任务(这是构建的入口点)来解决此问题。

The problem is that none of the usual build variables are populated - $(BuildDirectory), $(SolutionRoot) - all blank. 问题在于,没有填充任何通常的构建变量-$(BuildDirectory),$(SolutionRoot)-全部为空。 This pretty much means I can't invoke my ant task without hardcoding the paths (which I definitely can't do). 这几乎意味着我必须在不对路径进行硬编码的情况下才能调用我的ant任务(这绝对是我做不到的)。

Any ideas? 有任何想法吗?

您可能想看看Teamprise Build Extensions ,它允许从TFS构建Ant或Maven任务。

  1. If you don't already have one, create a task that will store and retrieve environment variables, you're definitely going to need them doing anything java related (I believe there is one in the MSBuild extension pack ) 如果您还没有一个,创建一个将存储和检索环境变量的任务,那么您肯定需要它们执行与Java相关的任何操作(我相信MSBuild扩展包中有一个)
  2. Create a custom task to wrap Ant or use the Script task from the MSBuild Community Tasks collection 创建一个自定义任务来包装Ant或使用MSBuild Community Tasks集合中的Script任务
  3. Run it a million times and fix the problems as you go, it's usually easier and faster to do this from the command line, so make friends with msbuild.exe inside the terminal 运行一百万次并随时解决问题,从命令行执行此操作通常更容易,更快,因此请在终端中使用msbuild.exe结交朋友

You should be able to pass around any info you want between environment variables, making whatever you want to do possible. 您应该能够在环境变量之间传递所需的任何信息,从而使您想做的一切成为可能。 I'm not going to recommend hard-coding paths to you, but you have to put the config somewhere and it's all a trade off of what you want to change and how you want things organized. 我不会向您推荐硬编码的路径,但是您必须将配置放在某处,这是您要更改的内容以及组织方式的全部权衡。 If you really need to, you can push all the config into a database and suck it down with one of the SQL tasks in the above links, but just remember you're adding a considerable amount of complexity that may be unnecessary. 如果确实需要,可以将所有配置推送到数据库中,并使用上述链接中的SQL任务之一将其吸取,但是请记住,您添加了相当多的不必要的复杂性。

Ask yourself: 问你自己:

  • how often is this value likely to change? 该值可能多久更改一次?
  • what is the full set of tasks that would need to be done if it changes? 更改后需要完成的全部任务是什么?

Write the answers to that down somewhere and make sure everybody on the team understands it. 将答案写下来,并确保团队中的每个人都理解。 When it comes to build systems in my opinion "less is more". 在我看来,构建系统时,“少即是多”。 Find the simplest way to do it, and do that until that becomes unacceptable and only then add complexity... TFS is complicated enough already. 找到最简单的方法,直到不能接受为止,然后再增加复杂性……TFS已经足够复杂了。

I think you are using the wrong tool for the job here - TFS will never be a good solution for building any other than .NET applications. 我认为您在这里使用错误的工具-TFS永远不是构建.NET应用程序以外的任何其他解决方案的好方法。 I think you are better off just using ant in a standalone capacity. 我认为您最好以独立功能使用ant。

Thanks for all the answers. 感谢所有的答案。

In the end I resorted to including an empty solution next to the build file. 最后,我求助于在构建文件旁边添加一个空解决方案。 This way all the variables are populated and I simply included a which did everything I wanted. 这样,所有变量都被填充,而我仅包含一个完成了我想要的所有操作的变量。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM